Showing posts with label simple calculation. Show all posts
Showing posts with label simple calculation. Show all posts

Sunday, 16 June 2013

java program for addition, subtraction, multiplication and division

import java.io.*;
class allprograms
{
    public static void main(String args[])
    {
        try
        {
            int a,b,c,d,e;
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter the first number");
            a=Integer.parseInt(cin.readLine());
            System.out.println("Enter the Second number");
            b=Integer.parseInt(cin.readLine());
            c=a+b;
            d=a-b;
            e=a*b;
            float f=b/a;
            System.out.println(a+" + "+b+" = "+c);
            System.out.println(a+" - "+b+" = "+d);
            System.out.println(a+" * "+b+" = "+e);
            System.out.println(b+" / "+a+" = "+f);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}