Код: Выделить всё
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
System.out.println("your result is " + result(a,b,c));
}
public static int result(int x, int y, int f) {
int result = 0;
result = switch (f) {
case 1 -> x + y;
case 2 -> x - y;
case 3 -> x * y;
case 4 -> x / y;
default -> 0;
};
return result;
}
}
Код: Выделить всё
if(x != 0 && y != 0) {
result = switch (f) {
case 1 -> x + y;
case 2 -> x - y;
case 3 -> x * y;
case 4 -> x / y;
default -> 0;
};
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... o-create-a