Find Maximum array
Array -- Find Maximum
Write a method that can find the maximum number from an int Array
Solution 1:
public static void main(String[] args) {
int[] arr = new int[]{2,4,6,8,20};
System.out.println(maxValue(arr));
public static int maxValue( int[] n ) {
int max = Integer.MIN_VALUE;
for(int each: n)
if(each > max)
max = each;
return max;
}
Solution 2:
public static int maxValue( int[] n ) {
Arrays.sort( n );
return n [ n.lenth-1 ];
}