使用两个整数求它们之间的倍数

Using two integers to find the multiples inbetween them

我正在尝试使用 '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,第二个是 30 并且输出是 5 10 15 30(你增加了(第一个输入)5) 所以如果你输入 10 和 25 输出应该是 10 20 25 递增(第一个输入)。 如果这就是您要解释的内容,那么您的代码应该如下所示

Scanner in = new Scanner(System.in);

   int N_small= 0, N_big = 0 ,i;

   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) {
         System.out.printf("The numbers are:");           
       for (i = N_small; i < N_big+1 ; i=i+N_small){
         if(i > N_big) System.out.println(N_big); else System.out.println(i);  

    }   
   }
  }