集册 Java实例教程 偶数计数器用

偶数计数器用

欢马劈雪     最近更新时间:2020-01-02 10:19:05

657
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用do-while循环而不是while循环的偶数计数器

public class Main/*来 自 nowjava - 时代Java*/

{

      public static void main(String[] args)

      {

            int number = 2;

            do

            {

                 System.out.print(number + " ");

                 number += 2;

            } while (number <= 20);

            System.out.println();

      }

}