Question: Rewrite the MinMax class shown down below so that it uses a for-each style for loop. (MUST USE JAVA - SIMPLE JAVA) class MinMax {

Rewrite the MinMax class shown down below so that it uses a for-each style for loop. (MUST USE JAVA - SIMPLE JAVA)

class MinMax { }

public static void main(String[] args) {

int[] nums = new int[10]; int min, max; }

nums[0] = 99;

nums[1] = -10;

nums[2] = 100123;

nums[3] = 18;

nums[4] = -978;

nums[5] = 5623;

nums[6] = 463;

nums[7] = -9;

nums[8] = 287;

nums[9] = 49;

min = max = nums[0];

for(int i=1; i < 10; i++) {

if(nums[i] < min) min = nums[i];

if(nums[i] > max)

max = nums[i]; }

System.out.println("min and max: " + min + " " + max);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!