FR

import java.util.*; public class FR { //You are given an array of studen grades titled grades. //Part A: Find the highest grade in the array //Part B: Sort the array from the lowest grade to the highest public static void main(String arg[]){ int[] grades = {90, 85, 75, 98, 68}; //Part A int max = 0; for (int i = 0; i < grades.length; i++){ if (grades[i] > max){ max = grades[i]; } } System.out.println("The highest grade is: " + max); //Part B int temp = 0; for (int i = 0; i < grades.length; i++){ for(int b = i + 1; b < grades.length; b++){ if (grades[b] < grades[i]){ temp = grades[i]; grades[i] = grades[b]; grades[b] = temp; } } } System.out.println(Arrays.toString(grades)); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.