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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site