我试图提示用户输入一个介于1和12之间的值。如果他们输入的值超出此范围(EX -15),我需要继续提示直到他们进入一个在1-12的值。当用户输入一个指定范围内的值时(1-12)它需要打印一个时间表,其中包含整数1乘以输入数字的结果。到目前为止,我相信我有这个布局一些什么正确的,但我知道我失去了一些东西,但无法弄清楚这里的代码:试图让用户输入介于两个值之间
package times_Table;
import java.util.Scanner;
public class Times_Table {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int TOTAL = 5;
System.out.print("Enter an integer between 1 and 12:");
int input = sc.nextInt();
int numbers = input;
//If the input is out of the range 1-12 keep going
//If the input is in the range of 1-12 stop
//Need to find a way to keep looping if the integer inputed is out of the range 1-12
while (numbers>1 && numbers<12) {
if (numbers<1 && numbers>12) {
for (int i = 1; i <= TOTAL; i++) {
for (int j = 1; j<=TOTAL; j++) {
System.out.print(i*j + "\t");
}
System.out.println();
}
} else {
if (numbers < 1 && numbers > 12) {
System.out.print("Enter an integer between 1 and 12:");
}
}
}
}
}
它会帮助你很多,如果你将通过代码在你的IDE调试步骤,看什么在发生每个陈述。你试过了吗? –
你需要重做你的'if/else'流程。应该是数字在里面,做数学运算,否则用'Scanner'再次请求输入。现在你的while循环正在使if else循环无用。 –
请注意澄清*它需要打印一个时间表,结果乘以整数1到输入数字... *? – aribeiro