集册 Java实例教程 返回任意数量的int值中的最大值。

返回任意数量的int值中的最大值。

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

475
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
返回任意数量的int值中的最大值。


//package com.nowjava;
/*来自 n  o  w  j  a  v  a . c o m*/

public class Main {

    public static void main(String[] argv) throws Exception {

        int arg = 2;

        System.out.println(max(arg));

    }


    /**

     Returns the largest of any number of int values.

     */

    public static int max(int... arg) {

        if (arg.length == 0) {

            System.out.println("Fatal Error: maximum of zero values.");

            System.exit(0);

        }


        int largest = arg[0];/*来自 NowJava.com - 时  代  Java*/

        for (
展开阅读全文