当用户输入“Y”值时,我试图将这个程序作为循环运行。我希望输入忽略大小写,以便用户也可以输入“y”或“n”。我会使用 equalsIgnoreCase() 方法吗?如果是这样,我是否想将我的 char 更改为布尔值?大约一个月后,我对 java 还是很陌生,所以任何帮助都将不胜感激。我已经玩了一段时间了,如果没有至少一个错误,我无法弄清楚。我让它循环的事实在这一点上是一个奇迹:)
char Again = 'Y';
while(Again == 'Y')
{
long product = 1, count = 0;
System.out.println("This program will generate a table of powers of a number.");
System.out.println("You just have to tell me what number: \n\n");
System.out.print("Enter an integer please: ");
int MyNum = Fred.nextInt();
while(count<5)
{ product = product * MyNum;
System.out.print(product + ",");
count = count + 1;
}
System.out.println("\nBye for now.....");
System.out.print("\n\n\n Try another number (y/n)?");
String Word = Fred.next();
Again = Word.charAt(0);
}