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