CALCULATOR IN JAVA
Program
import java.util.*;
class Switchcalculator
{
public static void main()
{
float a,b;
char c;
Scanner sc=new Scanner(System.in);
System.out.print("Enter two number : ");
a=sc.nextFloat();
b=sc.nextFloat();
System.out.println("+ - ");
System.out.println(" ");
System.out.println(" ");
System.out.println("* /");
c=sc.next().charAt(0);
switch(c)
{
case '+':
System.out.println(+a+" + "+b+" = "+a+b);
break;
case '*':
System.out.println(+a+" * "+b+" = "+a*b);
break;
case '-':
System.out.println(+a+" - "+b+" = "+(a-b));
break;
case '/':
System.out.println(+a+" / "+b+" = "+a/b);
break;
default:
System.out.println("Enter only ");
System.out.println("+ - ");
System.out.println(" ");
System.out.println(" ");
System.out.println("* /");
}
}
}
0 Comments