0
我想显示可以被两个用户输入整数使用'for'循环语句整除的数字。例如,如果我要输入5和30,我会得到“5 10 15 30”的输出。到目前为止,我已经有了非常基本的设置,但我一直在这里停滞不前。我如何使用变量在循环语句中相互分开?使用两个整数来找到它们之间的倍数
import java.util.Scanner;
public class practice4 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N_small= 0, N_big = 0;
System.out.printf("Enter the first number: ");
N_small = in.nextInt();
System.out.printf("Enter the second number: ");
N_big = in.nextInt();
if (N_small < N_big) {
for (int i = N_small; i == N_big; i++){
//Issue here! ***
System.out.printf("The numbers are: %d\n", i);
}
}
}
}
一个例子输出情况我不太清楚:
----------- Sample run 1:
Enter the first number: 5
Enter the second number: 30
The numbers are: 5 10 15 30
Bye
和
----------- Sample run 3:
Enter the first number: 7
Enter the second number: 25
The numbers are:
Bye.
任何帮助非常感谢,谢谢!
它需要的第一个整数的倍数,且整除第二,因此,例如验证码打印5 10 15 20 25 30,但20和25不能被30整除,因此需要将它们裁剪掉,我相信通过使用模函数,但我并不完全确定。 – lana
我想通了你的例子,谢谢。 – lana