Write a program that asks the user for two numbers, then lets the user choose the using 4
buttons, one for each operation. (+, -, *, / )The program should do the requested operation and
display the answer on the screen. Only Java plz
public class Main {
public static void main(String [] args) {
Scanner s = new Scanner(System.in);
System.out.println("Please enter two numbers:");
double a = s.nextDouble();
double b = s.nextDouble();
System.out.println("Now, please chooce one of the following signs: '+', '-', '*' or '/'")
switch(s.nextChar()) {
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;
}
}
}
Comments
Leave a comment