Answer to Question #260892 in HTML/JavaScript Web Application for ammar

Question #260892

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


1
Expert's answer
2021-11-04T00:24:13-0400
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;
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS