Write a program to design a calculator
06/02/2014 13:13
import java.io.*;
public class calculator
{
public static void main(String args[])throws IOException
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br =new BufferedReader(ir);
System.out.println("enter choice 1,2,3 or 4");
System.out.println("enter choice 1 to add");
System.out.println("enter choice 2 to subtract");
System.out.println("enter choice 3 to multiply");
System.out.println("enter choice 4 to divide");
int choice=Integer.parseInt(br.readLine());
System.out.println("enter two numbers");
double a=Double.parseDouble(br.readLine());
double b=Double.parseDouble(br.readLine());
switch(choice)
{
case 1: System.out.println(a+b);
break;
case 2: System.out.println(a-b);
break;
case 3: System.out.println(a*b);
break;
case 4: System.out.println(a/b);
break;
default: System.out.println("enter correct choice again");
}
}
}