使用下面的代码,即使我输入了一个大于 18 的数字,我也会得到这个结果。
运行:你多大了?21 你还没成年呢!构建成功(总时间:3 秒)
我是java新手,正在尝试自学,有人可以帮忙吗?
import java.util.Scanner;
public class Chapter8 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
// TODO code application logic here
//Excercise 15
System.out.print("How old are you? ");
int x = Integer.parseInt(reader.nextLine());
if (x > 18){
System.out.println("You have not reached the age of Majority yet!");
}else {
System.out.println("You have reached the age of Majority!");
}