Returns the largest of any number of int values. - Java Reflection

Java examples for Reflection:Method Return

Description

Returns the largest of any number of int values.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int arg = 2;
        System.out.println(max(arg));
    }/*from w  ww  .  j  av  a 2 s.co  m*/

    /**
     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];
        for (int i = 1; i < arg.length; i++)
            if (arg[i] > largest)
                largest = arg[i];
        return largest;
    }
}

Related Tutorials