exercise9_9.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 48 行

JAVA
48
字号
/**
 * Title:        Chapter 1, "Introduction to Java and JBuilder"
 * Description:  Examples for Chapter 1
 * Copyright:    Copyright (c) 2000
 * Company:      Armstrong Atlantic State University
 * @author Y. Daniel Liang
 * @version 1.0
 */

import java.util.Date;

public class Exercise9_9 {
  static int i;

  public Exercise9_9() {

  }

  public static void main(String[] args) {
    String[] strings = {"CS", "Math", "Biol", "Chem", "Phys", "Buss",
      "Law", "Educ", "Elec Engr", "Mech Engr"};

    Integer[] list = new Integer[10];

    Date[] dates = new Date[10];

    for (int i = 0; i < list.length; i++)
      list[i] = new Integer((int)(Math.random() * 100));

    for (int i = 0; i < list.length; i++)
      dates[i] = new Date();

    System.out.println("Max string is " + max(strings));
    System.out.println("Max integer is " + max(list));
    System.out.println("Max circle is " + max(dates));
  }

  public static Object max(Object[] a) {
    Comparable max = (Comparable)a[0];

    for (int i = 1; i < a.length; i++)
      if (max.compareTo(a[i]) < 0)
        max = (Comparable)a[i];

    return max;
  }
}

⌨️ 快捷键说明

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