Posts

Showing posts from April 12, 2016

Insertion sort technique upon strings In Java ISC

Program to perform Insertion sort technique upon strings. class Insertstring //start of class { public void accept (String str[]) //start of method { String key=" ";int j=0; int n=str.length; for( int i=1;i<n;i++) { key= str [i]; j=i-1; while ( j>=0 && key.compareTo(str[j])<0){ str[j+1]=str[j]; j--; } str[j+1]=key; } System.out.println("The output in ascending order"); for (int i=0;i<n;i++) { System.out.println(str[i]); } }//end of method }//end of class OUTPUT--- The output in ascending order ANIK IS LOVE

Recursive Series In Java (1) 1/2+(1+1)/2^2+(1+1+2)/2^3+......n terms.(2) 1!/X^2-2!/X^3+......n terms.

Menu driven recursive program to perform.          (1)  1/2+(1+1)/2^2+(1+1+2)/2^3+......n terms.          (2) 1!/X^2-2!/X^3+......n terms. class Recursion{      public double s1(int N){          if(N==0)          return 0;          else          return(fibo(N)/Math.pow(2,N)+s1(N-1));         }//s1         public double s2(int N,int x){             if(N==0)             return 0;             else if(N%2==1)             return((fact(N)/Math.pow(x,N+1))+s2(N-1,x));             else             return((fact(N)/Math.pow(x,N+1))+s2(N-1,x));         }//s2     ...

Recursive program to extract digits and print them in words.

Recursive program to extract digits and print them in words. class digword //start of class { public void accept ( int num ) { System.out.println(" The number is "+ "\t\t"+ num); int p= revdig( num); } public int revdig ( int k) { String a[]={"zero","one","two","three","four","five","six","seven","eight","nine"}; if (k==0){ return 0; } else { int r=k%10; System.out.println("the number"+"\t\t"+r+"\t\t"+ "in words"+"\t" +a[r]); } return revdig(k/10); }// end of method }// end of class OUTPUT--- The number is 2442441 the number 1 in words one the number 4 in words four the number 4 in words four the number 2 in words two the number 4 in words four the number 4 in words four the number 2 in words two

Menu driven recursive program to perform.(1)Calculate Factorial.(2)sum of digits of a multidigit number.(3)value of x^n.(4)multiplication of 2 numbers.

Menu driven recursive program to perform.         (1)Calculate Factorial.         (2)sum of digits of a multidigit number.          (3)value of x^n.          (4)multiplication of 2 numbers. import java.util.*; class Menudriven{     public static void main(){         Scanner sc=new Scanner(System.in);         System.out.println("Enter 1 for factorial");         System.out.println("Enter 2 for sum of digits of a multididgit number");         System.out.println("Enter 3 for value of x^n");         System.out.println("Enter 4 for multiplication of 2 numbers");         int a,b,c;         System.out.println("Enter your choice");         c=sc.nextInt();         switch(c){         ...

Menu driven recursive(1)Fibonacci Series.(2)Tribonacci Series.

Menu driven recursive program to perform.         (1)Fibonacci Series.         (2)Tribonacci Series. import java.util.*; class Recursion_fibtribseries{ public void accept(){ Scanner sc=new Scanner(System.in); System.out.println("Enter your choice: Press 1 for fibonacci series & press 2 for tribonacci series"); int n=sc.nextInt(); switch(n) { case 1 : System.out.println("Enter the number of terms"); System.out.println("The fibonacci series"); int num = sc.nextInt(); for (int i=1;i<=num;i++){ int fib= fibo (i); System.out.println(fib+ "\t\t"); } break; case 2: System.out.println("Enter the number of terms"); System.out.println("The tribonacci series"); int num1 = sc.nextInt(); for (int i=1;i<=num1;i++){ int trib= tribo (i); System.out.println(trib+ "\t\t"); } break; default : System.out.println(" Wrong Choice "); }} int fibo ( int i){ if (i==0) return -1; else if ( ...

Recursive program to calculate Greatest Common Divisor Of 2 programs.

Recursive program to calculate Greatest Common Divisor Of 2 programs. class GCD{ public void accept(int n1,int n2){ int big=(n1>n2)?n1:n2; int small=(n1<n2)?n1:n2; int gcd=Grcodi(big,small); System.out.print("The greatest common divisor"+"\t\t"+gcd); } int Grcodi(int p,int q){ if(q==0) return p; return Grcodi(q,p%q); }//accept }//End of class OUTPUT--- When Input is 3 & 2 The greatest common divisor 1

Recursive program to perform the Binary search technique.

Recursive program to perform the Binary search technique. import java.util.*; class BS{     static int a[];     public void check(int lb,int ub,int s){         if(lb>ub)         System.out.println("NOT FOUND");         else         {             int m=(lb+ub)/2;             if(a[m]==s)             System.out.println(s+" Found at "+(m+1)+"th position");             else             if(s>a[m])             check(m+1,ub,s);             else             check(lb,m-1,s);         }     }     public static void main(){         Scanner sc=new Scanner(System.in);    ...

Menu Driven recursive program to.(1)calculate reverse of a string.(2)calculate reverse of a number.

Menu Driven recursive program to.          (1)calculate reverse of a string.          (2)calculate reverse of a number. import java.util.*; class Reverse{     public String rev(String s){         if(s.length()==1)             return s;         else             return(rev(s.substring(1))+s.charAt(0));     }  public static void main(){         Scanner sc=new Scanner(System.in);         System.out.println("Enter 1 for reversing a string or 2 for reversing a number");         int c=sc.nextInt();         sc.nextLine();         Reverse r=new Reverse();         switch(c){             case 1:System.out.println("Enter a String");        ...

Recursive program to convert a decimal number to any base.

Recursive program to convert a decimal number to any base. import java.util.*; class dectoanyrec{     public String anyB(int n,int b){         if(n<b)         return n<=9?""+n:""+(char)(n+55);         else         return anyB(n/b,b)+(n%b<=9?""+n%b:(char)(n%b+55));     }//anyB     public static void main(){          Scanner sc=new Scanner(System.in);         System.out.println("Enter any decimal number");         int n=sc.nextInt();         System.out.println("Enter the base");         int b=sc.nextInt();         dectoanyrec DR=new dectoanyrec();         System.out.println("The number in the base  "+b+"  Is  "+DR.anyB(n,b));     }//main }//class  OUTPUT--- Enter any decimal numb...

Symmetric Matrix In Java ISC

11---Program to declare a square matrix A[ ] [ ] of order (M x M) such that M must be greater than 2 and less than 10 and check whether it is a Symmetric matrix or not. class Symmetric{ //start of class public void accept(int as[][]){ int r=as.length; int c=as[0].length;int d=0; if(c!=r|| c<2||c>10){ System.out.println("Not a Symmetric matrix"); System.exit(1); } for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ if(as[i][j]!=as[j][i]) d++; }} if(d==0) System.out.println("The Given matix is Symmetric"); else System.out.println("not a symmetric matrix"); }}//end of class OUTPUT--- WHEN INPUT IS {{1,2,3},{5,6,7}} OUTPUT IS Not a Symmetric matrix

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to     n*n, taking ‘n’ as input. import java.util.*; class Circular_Matrix     {      //start of class         public static void main()         {             Scanner sc=new Scanner(System.in);             System.out.print("Enter the number of elements : ");             int n=sc.nextInt();             int A[][]=new int[n][n];             int k=1, c1=0, c2=n-1, r1=0, r2=n-1;             while(k<=n*n)                 {                     for(int i=c1;i<=c2;i++)                 ...

Saddle Point Matrix In Java ISC

Program to find the SADDLE POINT for the matrix. class Saddlepoint{ //start of class public void accept(int a[][]){ int n=0; int r=a.length; int c=a[0].length; for(int i=0;i<r;i++){ int min=a[i][0]; int p=0; for(int j=0;j<c;j++){ if(a[i][j]<min){ min=a[i][j]; p=j; }} int max=a[0][p]; for(int k=0;k<r;k++){ if(a[k][p]>max){ max=a[k][p];  n=k; }} if(n==i){ System.out.println("The  Saddle point "+a[i][p]); break; }} }}//end of class OUTPUT---WHEN INPUT IS {{1,2,2},{2,3,5}} The  Saddle point 2

Upper Triangular Matrix In Java ISC

Program to input a 2-D square matrix and check whether it is a Upper Triangular Matrix or not. import java.util.*; class UpperTriangularMatrix {     public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.print("Enter the size of the matrix : ");         int m=sc.nextInt();         int A[][]=new int[m][m];         for(int i=0;i<m;i++)         {             for(int j=0;j<m;j++)             {                 System.out.print("Enter an element : ");                 A[i][j]=sc.nextInt();             }         }         System.out.println("The Matrix is : ");       ...

Lower Triangular Matrix In Java ISC

Program to input a 2-D square matrix and check whether it is a Lower Triangular Matrix or not. import java.util.*; class LowerTriangularMatrix {     public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.print("Enter the size of the matrix : ");         int m=sc.nextInt();         int A[][]=new int[m][m];         for(int i=0;i<m;i++)         {             for(int j=0;j<m;j++)             {                 System.out.print("Enter an element : ");                 A[i][j]=sc.nextInt();             }         }         System.out.println("The Matrix is : ");       ...

Multiply Matrices In Java ISC

Program to multiply two given matrices. class Multiplymatrices{ //start of class public void accept(int a[][],int b[][]){ int r1=a.length; int r2=b.length; int c1=a[0].length; int c2=b[0].length; int c[][]=new int[r1][c2]; if(r2==c1){ for(int i=0;i<r1;i++){ for(int j=0;j<c2;j++){ for(int k=0;k<c1;k++){ c[i][j]+=a[i][k]*b[k][j]; }}} System.out.println("the new matrix"); for(int i=0;i<r1;i++){ for(int j=0;j<c2;j++){ System.out.print(c[i][j]+" "); } System.out.println(); } } else { System.out.println("Wrong input"); System.exit(1); }}}//end of class OUTPUT--- Enter the value of r1 then c1 and r2 and c2 2 2 2 2 Enter any number 4 Enter any number 3 Enter any number 4 Enter any number 3 Enter any number 4 Enter any number 3 Enter any number 4 Enter any number 3 2821 2821

Pascal Triangle In Java ISC

-Program to generate a Pascal’s Triangle class PascalTriangle { //start of class public void accept(int n) { int a[][]=new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<=i;j++){ if(i==j||j==0) a[i][j]=1; else a[i][j]=a[i-1][j]+a[i-1][j-1]; }} for(int i=0;i<n;i++){ for(int k=1;k<n-1;k++){ System.out.println(" "); } for(int j=0; j<=i;j++){ System.out.print(a[i][j]+" "); } System.out.println(); }}}//end of class OUTPUT--- 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 

Decimal To Binary In Java ISC & ICSE

Program to convert Decimal to Binary class DecimaltoBinary{//start of class public void accept(int n){ String str=" "; while(n!=0){ int r=n%2; n=n/2; str=Integer.toString(r)+str; } System.out.println("The binary form is "+str); }}//end of class OUTPUT--- WHEN INPUT IS 110 The binary form is 1101110 

Lucky Number In Java ISC

Write a program to generate and print lucky numbers less than a given number N. import java.util.*; class LuckyNumbers {//start of class public void accept(int n) {     int a[]=new int[n];     int c=n;     for(int i=0;i<n;i++){         a[i]=i+1;     } int del=1; System.out.println("Lucky Number Operation :n"); while(del<n) { for(int i=del; i<n; i+=del) { for(int j=i; j<n-1; j++) { a[j]=a[j+1]; } n--; } del++;     for(int i=0;i<n;i++){         System.out.print(a[i]+"");     }     System.out.println();  } //end of while System.out.print("Hence, the Lucky Numbers Less than equal to  " + c + " are : "); for(int i=0; i<n; i++) { System.out.print(a[i]+"   "); } }}//end of class OTPUT--- Hence, the Lucky Numbers Less than equal to  24 are : 1   3   7   13   19

Smith Number In Java ISC

A  Smith number is a composite number, the sum of whose digits is the sum of the digits o     its prime factors obtained as a result of prime factorization. import java.util.*; class Smith { //start of class     public int sumDig(int n)     {         int s1=0;         while(n>0)         {             s1=s1+n%10;             n=n/10;         }         return s1;     }     public int sumPrime(int n)     {         int i=2, s2=0;         while(n>1)         {             if(n%i==0)             {                 s2=s2+sumDig(i);                 n...