import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" in the terminal window.
Scanner quest = new Scanner(System.in);enter code here
System.out.println("How old are you?: ");
int num = quest.nextInt();
if (num <= 12){
System.out.println("You are too young to be on the computer!!!!");
} else if (num >=13 && num <= 17){
System.out.println("Welcome young teen");
} else if (17 < num && num <= 60){
System.out.println("Welcome adult");
} else if (60 < num){
System.out.println("Welcome senior citizen!!");
} else{
System.out.println("Invalid age.");
}
}
}
當我輸入一個負數時,它只屬於「你太年輕了,不能在電腦上!!!!」而不是顯示「無效的年齡」。我試圖改變條件,但它似乎沒有工作。負數不被識別
這是因爲這是第一個條件。做'num <= 12 && num> 0'什麼的。 – Li357
負值使第一個「if」爲真,然後顯示它所顯示的內容。 – SHG
該死的新的數學模式,其中-1> 12! – John3136