largest in array 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: second largest value in array java 8
public class ThirdLargestNumberInAnArray {
public static void main(String args[]){
int temp, size;
int array[] = {10, 20, 25, 63, 96, 57};
size = array.length;
for(int i = 0; i<size; i++ ){
for(int j = i+1; j<size; j++){
if(array[i]>array[j]){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println("Third second largest number is:: "+array[size-2]);
}
}