Posts

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