java find the lowest biggest number in an array code example
Example 1: find the largest and smallest number in an unsorted integer array in Java
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Number of integers to enter:");
int numberEnter = keyboard.nextInt();
int numbers[] = new int[numberEnter];
int pos = 0;
do {
System.out.printf("Please enter integer #%d/%d:%n", pos, numberEnter);
numbers[pos++] = keyboard.nextInt();
} while (pos < numberEnter && keyboard.hasNextInt());
int min = numbers[0];
int max = numbers[0];
for (pos = 1; pos < numbers.length; pos++) {
if (numbers[pos] < min) {
min = numbers[pos];
}
if (numbers[pos] > max) {
max = numbers[pos];
}
}
System.out.printf("%s Min: %d Max: %d%n", Arrays.toString(numbers),
min, max);
}
Example 2: 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);