highestvalue.java

来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 48 行

JAVA
48
字号
import java.io.*;
import javagently.*;

class HighestValue {

  /* The Highest Value Program    by  J M Bishop  Aug 1996
   * -------------------------    Java 1.1 October 1997
   *                              Java 2 and new Stream class
   *                              May 2000
   *
   * Finds the highest in a list of numbers.
   * Illustrates the if-statement
   */

  HighestValue () throws IOException{

    Stream in = new Stream (System.in);

    System.out.println("*****  Finding the highest number *****");

   // Find out how many numbers will be coming
    System.out.print("How many numbers (1 or more)?");
    int n = in.readInt();

   // Start off the sequence
    System.out.println("Type them in");
    System.out.print("1>");
    int highest = in.readInt();

   // Read and check the rest of the numbers
    int number;
    for (int i = 2; i <= n; i++) {
      System.out.print(i+">");
      number = in.readInt();
      if (number > highest) {
        highest = number;
      }
    }

    System.out.println("That's enough, thanks");
    System.out.println("The highest number was " + highest);
  }

  public static void main(String[] args) throws IOException {
    new HighestValue ();
  }
}

⌨️ 快捷键说明

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