以下のコードを使用すると、18 より大きい数値を入力しても、この結果が得られ
ます。 run: How old are you? 21 まだ成年に達していません!BUILD SUCCESSFUL (合計時間: 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!");
}