Let x 1 3 5 7 9 11 13 2 4 6 8 10 12 Use for loop and max fu
Let x = [1 3 5 7 9 11 13 2 4 6 8 10 12]. Use for loop and max function to find three largest values in x.
Solution
public class Max3 {
public static void main(String args[]) {
int l;
int large[] = new int[4];
int array[] = { 1, 3, 5, 7, 9, 11, 13, 2, 4, 6, 8, 10, 12 };
int maximum = 0, index;
for (int k = 1; k < 4; k++) {
maximum = array[0];
index = 0;
for (l = 1; l < array.length; l++) {
if (maximum < array[l]) {
maximum = array[l];
index = l;
}
}
large[k] = maximum;
array[index] = Integer.MIN_VALUE;
System.out.println(\"largest \" + k + \" : \" + large[k]);
}
}
}
![Let x = [1 3 5 7 9 11 13 2 4 6 8 10 12]. Use for loop and max function to find three largest values in x.Solution public class Max3 { public static void main(St Let x = [1 3 5 7 9 11 13 2 4 6 8 10 12]. Use for loop and max function to find three largest values in x.Solution public class Max3 { public static void main(St](/WebImages/3/let-x-1-3-5-7-9-11-13-2-4-6-8-10-12-use-for-loop-and-max-fu-970926-1761499550-0.webp)