我正在尝试制作一个程序,输入用户的姓名和年龄,然后询问用户他/她想知道什么信息。这是程序:
import java.util.Scanner;
public class name_and_age {
static Scanner key = new Scanner(System.in);
public static void main(String args[]) {
String name = "NAME";
String age = "AGE";
System.out.println("What is your name?");
String a = key.nextLine();
System.out.println("What is your age?");
int b = key.nextInt();
while()
{
System.out.println("What do you want to know?");
String i = key.nextLine();
if(i.equals(name))
{
System.out.println("Your name is "+ a);
}
if(i.equals(age))
{
System.out.println("Your age is" + b);
}
else
{
System.out.println("Please either enter age or name");
}
}
}
}
我对在 while 循环中放入什么感到困惑,因为我想要类似的东西,
while( (i.equals(name)) || (i.equals(age)) )除了我想将不等于放在等于的位置之外。我该怎么办?
小怪兽爱吃肉
相关分类