我的“if”语句似乎不起作用,无论我输入什么似乎总是默认为我的“else”语句。例如,如果我输入整数“1”或“2”,其中有“if”语句与之关联,它仍然默认为“else”。任何帮助,将不胜感激 :)
String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1. Custom 2. Infinite"); //test choice
n = Integer.parseInt(number);
while (n < 0 || n > 2) {
if (n == 1) {
String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
integer = Integer.parseInt(number2);
while (integer < 0) {
while (x < integer) {
g.drawString("hi", 200, y);
x += 1;
y = y + 40; //test
}//end while
}
}//end if
else if (n == 2) {
while (1 == 1);
}//end if
else;
}
g.drawString("Please pick a valid choice", 200, 200);