give me examples of bubble sort algorithm in java programming language.
calculate the summation of rows, and average of rows:
int[][] numbers = { {3,6,12}, {1,3,5,7,9}, {7,15}, {5,4,9,13,12,7,6}, {8,9,11,12} }; int total; int[] avg = new int[5]; for (int i = 0; i < numbers.length; i++) { total = 0; for(int j = 0; j < numbers[i].length; j++) total += numbers[i][j]; avg[i] = total / numbers[i].length; } sort(avg); System.out.println(); for (int i = 0; i < avg.length; i++) { System.out.print(avg[i] + " "); } } //bubble sort: public static void sort(int[] array) { int temp; for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] > array[j] ) { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
calculate the summation of rows, and average of rows:
need an explanation for this answer? contact us directly to get an explanation for this answer