find greatest no in array in java code example
Example 1: java find biggest number in array
for (int counter = 1; counter < decMax.length; counter++)
{
if (decMax[counter] > max)
{
max = decMax[counter];
}
}
System.out.println("The highest maximum for the December is: " + max);
Example 2: greatest element in array in java
private static int largest(int[] arr) {
int i = 0;
int index = 0;
for(int c = 0;c < arr.length;c++){
if(i < arr[c]){
i = arr[c];
index = c;
}
}
return i;
}