testwhile.java

来自「此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码」· Java 代码 · 共 27 行

JAVA
27
字号
// TestWhile.java: Test the while loop
public class TestWhile
{
  // Main method
  public static void main(String[] args)
  {
    int data;
    int sum = 0;

    // Read an initial data
    System.out.println("Enter an int value");
    data = MyInput.readInt();

    // Keep reading data until the input is 0
    while (data != 0)
    {
      sum += data;

      System.out.println(
        "Enter an int value, the program exits if the input is 0");
      data = MyInput.readInt();
    }

    System.out.println("The sum is " + sum);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?