Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

  1. (Swap.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the position (or index) of the maximum and minimum values in the array, and swap them (i.e., move the biggest element to the position of the smallest, and move the smallest element to the position of the biggest). At the end, apply

System.out.println(Arrays.toString(xxxx))

to print out the new status of such an array xxxx. If necessary, include

import java.util.*;

or

import java.util.Arrays;

CODE:

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 to Expert-Tailored 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

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions