Answer the question
In order to leave comments, you need to log in
Why does netBeans require me to convert a chain of if statements into a switch statement?
In this case, the program runs without errors. Here is the code:
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String[] args) {
System.out.println("Пожалуйста введите A");
int a = new Scanner(System.in).nextInt();
System.out.println("Пожалуйста введите B");
int b = new Scanner(System.in).nextInt();
System.out.println("Поажлуйста введите оператор {+,-,*,/}");
char ch = new Scanner(System.in).nextLine().charAt(0);
if (ch == '+') {
System.out.println("a + b = " + (a + b));
} else if (ch == '-') {
System.out.println("a - b = " + (a - b));
} else if (ch == '*'){
System.out.println("a * b = " + (a * b));
} else if (ch == '/') {
System.out.println("a / b = " + (a / b));
} else {
System.out.println("Неподдерживаемый оператор: " + ch);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question