Posts

Infix To Postfix In Java Using Stack

25--- Write a program to convert a given infix expression to postfix expression using stack. import java.util.*; import java.util.*; class Infix2Postfix {  char s[]=new char[100];     int top=-1;     void push(char ch){         top=top+1;         s[top]=ch;     }     char pop(){         char ch;         ch=s[top];         top=top-1;         return(ch);     }     int pre(char ch){         switch(ch){             case'^':return 3;             case'*':return 2;             case'/':return 2;             case'+':return 1;             case'-':return 1;         }         return 0; ...

Hit the nail on the head program in Java

24---Write a program to read a sentence which terminates with a full stop(.).The words are to          be sperated by a single blank space and are in lower case.Arrange the words in ascending          order according to the length of the words.If 2 words are of same length then the word          occuring first in the input sentence should come first.For for input and output the          sentence must begin with   upper case.          SAMPLE INPUT : Hit the nail on the head.          SAMPLE OUTPUT : On hit the the nail head. import java.util.*; class LengthWise{     public static void main()     {Scanner sc=new Scanner(System.in);         String s,t,x="",y;         int i,l;         System.out.println("Enter a String");       ...

Date difference in Java

23---WAP to perform date difference.Accept 2 dates in  the format dd/mm/yy.          check the dates are valid or not and find difference between 2 dates.          SAMPLE INPUT         Date 1:20/12/2012                               Date 2:11/02/2013          SAMPLE OUTPUT     Difference=54 days import java.util.*; class Date_Difference {     Scanner sc=new Scanner(System.in); int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //function for checking for Leap Year int isLeap(int y)     {         if((y%400==0) || ((y%100!=0)&&(y%4==0)))             return 29;         else             return 28;     } //function for checking date validation boole...

Wap to input an integer array of order m*n and arrange them along the ROW

22---Wap to input an integer array of order m*n and arrange them along the         ROW in a way given below.         SAMPLE INPUT                                           SAMPLE OUTPUT         3 2 4 1 5                                                       5 3 1 2 4         4 5 7 9 0                                                       9 5 0 4 7 import java.util.*; class Pendulum_Array {     public static void main()     {         Scanner sc=new Scanner(System.in);       ...

Union of 2 sets,A and B(2)Intersection of 2 sets,A and B.(3)Show that operation A-B and B-A are always false for sets.

21---Program to perform.         (1)Union of 2 sets,A and B.          (2)Intersection of 2 sets,A and B.          (3)Show that operation A-B and B-A are always false for sets. import java.util.*; class U_I_M {    private int l1,l2;    public void intersection(int a[],int b[]){        int i,j,k=0,l3;        l1=a.length;        l2=b.length;        l3=Math.min(l1,l2);        int c[]=new int[l3];        for(i=0;i<l1;i++){            for(j=0;j<l2;j++){                if(a[i]==b[j]){                    c[k++]=a[i];                    break;               ...

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);    ...