Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Write a counter controlled loop to solve the following problems. Each one will involve an array (MinMax.java) Read in 25 ints from the keyboard,

2. Write a counter controlled loop to solve the following problems. Each one will involve an array

(MinMax.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the maximum and minimum values in such an array, and display them on the screen.

public class Array-Assignment {

public static void main(String [] args) {

int [] x = new int[3];

int [] y = {3, 5, 9, 2};

x[2] = y[3];

x[0]++;

y[1] += y[2] * y[0];

int [] z = x;

x = y;

x[1] = 4;

}

}

public class Array-Length {

public static void main(String [] args) {

int [] x = new int[4];

int [] y = {};

int [] z = {0};

System.out.println("x has " + x.length + " elements");

System.out.println("y has " + y.length + " elements");

System.out.println("z has " + z.length + " elements");

}

}

public class Array-With-Loop1 {

public static void main(String [] args) {

int [] x = {-4, 9, 8, 2, -5, 7, 1};

for(int i=1; i

x[i] += x[i-1]; // notice: += instead of =

}

}

}

public class Array-With-Loop2 {

public static void main(String [] args) {

int [] x = {-4, 9, 8, 2, -5, 7, 1};

for(int i=1; i

x[i] = x[i-1];

}

}

}

public class Array-With-Loop3 {

public static void main(String [] args) {

int [] x = {-4, 9, 8, 2, -5, 7, 1};

int val = 0;

for(int i=1; i

val = val + x[i];

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions