Answer:
See explaination
Explanation:
import java.util.Scanner;
public class BubbleBubbleStarter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double arr[] = new double[10];
System.out.println("Enter 10 GPA values: ");
for (int i = 0; i < 10; i++)
arr[i] = sc.nextDouble();
sc.close();
System.out.println("My list before sorting is: ");
printlist(arr);
bubbleSort(arr);
System.out.println("My list after sorting is: ");
printlist(arr);
}
static void bubbleSort(double[] list) {
boolean changed = true;
do {
changed = false;
for (int j = 0; j < list.length - 1; j++) {
if (list[j] > list[j + 1]) {
double temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
changed = true;
}
}
} while (changed);
}
static void printlist(double list[]) {
for (int j = 0; j < list.length; j++) {
System.out.println(list[j]);
}
}
}