我在我的程序中创建是/否输入时遇到问题。我希望用户能够在最后一个打印语句之后输入 ay/n,但我不太确定如何实现它。我知道它很可能包含一个布尔值或 if/else 语句,但我不太确定。有什么帮助吗?
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class Person
{
public static void main(String[]args)
{
int age;
String name;
Scanner scan = new Scanner(System.in);
System.out.println("Enter in your age.");
age = scan.nextInt();
if (age >= 10 && age < 18)
{
System.out.println("So you're a kid, huh?");
}
else if (age < 10)
{
System.out.println("Nice try.");
System.exit(0);
}
else if (age >= 18 && age <= 100)
{
System.out.println("So you're an adult, huh?");
}
else if (age > 100)
{
System.out.println("Nice try.");
System.exit(0);
}
Scanner in = new Scanner(System.in);
System.out.println("Enter in your name");
name = in.nextLine();
System.out.println("So you're " + age + " years old and your name is " + name + "?");
System.out.println("y/n");
}
}