-3

我正在创建扫描仪测试。我设法打印了偶数 1-50。我想做一个扫描代码,这样当用户输入 8 时,它将打印 8-50 的所有偶数。

导入 java.util.Scanner;

公共类 ModulusCalculation {

public static void main(String[] args)
{
    int endLimit = 50;

    System.out.println("WE ARE GOING TO PRINT EVEN NUMBER FROM 1 AND " + endLimit);
    Scanner input = new Scanner(System.in); 
    for (int startingPoint = 1; startingPoint <= endLimit; startingPoint++)
    {
        if (startingPoint % 2 == 0)
        {
            input.nextLine();
            System.out.println(+startingPoint);
        }
    }

}

}

4

1 回答 1

0

不需要阅读 input.nextLine(); 在 for 循环中。

第 1 步:读取一个起始整数值

第 2 步: for (int startPoint = startinteger;startingPoint <= endLimit;startingPoint++)

STEP3:根据for循环内的条件打印所有偶数

于 2012-12-12T01:51:59.423 回答