这是我的 if-else 语句:
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int number;
System.out.println("Enter Integer: ");
number = input.nextInt();
if (number % 7 == 0) {
System.out.println(number + " is divisible by 7");
}
else {
System.out.println(number + " isn't divisible by 7");
}
}
最佳答案
不用介意开关 - 你也不需要。
您可以将其放入一个语句中:
System.out.println(number + " is" + (number % 7 == 0 ? "" : "n't") + " divisible by 7");
关于java - 如何将 if-else 语句变成 switch 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21571240/