Posts

Showing posts from April 16, 2016

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