Write a program to create an array in order to store 30 numbers. Then display the highest number and second highest number present in it using bubble sorting.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[30];
for (int i = 0; i < array.length; i++) {
array[i] = in.nextInt();
}
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[i] > array[j]) {
int tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
System.out.println(array[array.length - 1] + " " + array[array.length - 2]);
}
}
Comments
Leave a comment