Hands-on Programming Exercises — Ch. 7-8
Arrays.sort). Use nested loops and swapping. Print the array before and after sorting.for loops. Outer: for (int i = 0; i < 4; i++). Inner: for (int j = i + 1; j < 5; j++). If grades[i] > grades[j], swap them using a temp variable: int temp = grades[i]; grades[i] = grades[j]; grades[j] = temp;.for (int i = 0; i < n - 1; i++). Inner: for (int j = i + 1; j < n; j++). If prices[i] < prices[j] (notice the < instead of >), swap: double temp = prices[i]; prices[i] = prices[j]; prices[j] = temp;."ID not found".boolean found = false;. Loop: for (int i = 0; i < n; i++). Inside: if (ids[i] == target) → print "Found at index: " + i, set found = true;, and break;. After the loop: if (!found) System.out.println("ID not found");.Arrays.sort(). Print the sorted array using Arrays.toString(). Then read a target value and use Arrays.binarySearch() to find it. Print the result — if index >= 0, it's found; otherwise it's not.Arrays.sort(scores);. Print: System.out.println("Sorted: " + Arrays.toString(scores));. Search: int index = Arrays.binarySearch(scores, target);. Then: if (index >= 0) print found with index, else print "Score not found".for (int i = 0; i < n - 1; i++), inner for (int j = i + 1; j < n; j++). If scores[i] < scores[j], swap with temp. For top 3: int top = Math.min(3, n); then for (int i = 0; i < top; i++) print places[i] + " place: " + scores[i].