Java 如果存在';它已经是if语句了
我看过其他帖子,但我不知道什么时候为我的程序运行输入while循环或for循环,直到它满足条件,即输入一个介于1和20之间的数字,然后运行代码Java 如果存在';它已经是if语句了,java,Java,我看过其他帖子,但我不知道什么时候为我的程序运行输入while循环或for循环,直到它满足条件,即输入一个介于1和20之间的数字,然后运行代码 import java.util.Scanner; public class MultiplicationTable { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number, total;
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number, total;
System.out.println("Please enter an integer from 1 to 20:");
number = scanner.nextInt();
if (number >= 21){
System.out.println("Your integer must be between 1 and 20.");
}
else if ( number <= 0){
System.out.println("Your integer must be between 1 and 20.");
}
else {
for(int i = 1; i<=20; i++){
total = number * i;
System.out.println(i + " X " + number + " = " + total);
}
}
}
}
import java.util.Scanner;
公共类乘法表{
公共静态void main(字符串[]args){
扫描仪=新的扫描仪(System.in);
整数,总数;
System.out.println(“请输入1到20之间的整数:”;
编号=scanner.nextInt();
如果(数字>=21){
System.out.println(“您的整数必须介于1和20之间”);
}
否则,如果(数字在扫描仪输入周围放置一个while循环
while(number < 0 || number > 20)
{
number = scanner.nextInt();
// if statements here
}
你的问题不清楚。或者是一个do
-while
循环。
int number = -1;