1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elanso [62]
3 years ago
6

1. Complete the following program so that it computes the maximum and minimum of the elements in the array. Write the program so

that it works even if the dimensions of the rows and columns are changed. (Use length rather than hard-coded numbers.)
Think carefully about how max and min should be initialized. Debug your program by editing the array. Change it in unexpected ways, such as all negative values, or the largest element as the last, or first, or all elements the same.
import java.io.* ;
class ArrayMaxMin
{
public static void main ( String[] args )
{
int[][] data = { {3, 2, 5},
{1, 4, 4, 8, 13},
{9, 1, 0, 2},
{0, 2, 6, 3, -1, -8} };
// declare and initialize the max and the min
???
//
for ( int row=0; row < data.length; row++)
{
for ( int col=0; col < ???; col++)
{
???
}
}
// write out the results
System.out.println( "max = " + max + "; min = " + min );
}
}
2. Modify the program so that it computes and prints the largest element in each row.
Requirements: Looping, bounds checking, initializer lists.
Computers and Technology
1 answer:
allochka39001 [22]3 years ago
5 0

Answer:

See Explanation

Explanation:

The line by line explanation of the modified program is as follows:

(1)

min is declared and initialized to the highest possible integer and max is declared and initialized to the least possible integer

int min,max;

min = Integer.MAX_VALUE; max = Integer.MIN_VALUE;

This iterates through each row. Because each row has a different number of elements, the row length of each is calculated using data[row].length

for ( int col=0; col< data[row].length; col++){

The following if statements get the minimum and the maximum elements of the array

   if(data[row][col] < min){         min = data[row][col];    }

   if(data[row][col] > max){         max = data[row][col];     }

(2):

The loop remains the same, however, the print statement is adjusted upward to make comparison between each row and the highest of each row is printed after the comparison

for ( int row=0; row < data.length; row++){

for ( int col=0; col< data[row].length; col++){

   if(data[row][col] > max){         max = data[row][col];     }

}

System.out.println( "max = " + max);

max = Integer.MIN_VALUE; }

<em>See attachment for complete program that answers (1) and (2)</em>

Download txt
You might be interested in
Which is most likely to cause confusion, hinder thinking, and prevent quick access to resources in a study environment? phones c
OverLord2011 [107]
Clutter will cause the most problems when you are trying to study because <span>If you’re unable to get through the material clogging up your </span>neural<span> networks, so the theory goes, you’ll be slower and less efficient in processing information. As a result, you’ll be incapacitated when it comes to short-term memory tasks, and even in longer-range mental exercises when you have to come up with information you should know, such as names of people, that you can no longer find within your disorganized repository of knowledge.

Hope this helps, 

kwrob</span>
3 0
4 years ago
Read 2 more answers
Complete the following sentence.
pishuonlain [190]

Answer: Career

Explanation: because

7 0
3 years ago
How do you flatten a 2D array to become a 1D array in Java?
Leni [432]

Answer:

With Guava, you can use either

int[] all = Ints.concat(originalArray);

or

int[] all = Ints.concat(a, b, c);

Explanation:

Use GUAVA

4 0
2 years ago
To use a jQuery UI widget, you must code two things in the way that’s prescribed for the widget. What are they?
Natasha2012 [34]

Answer:

the jQuery code and the jQuery UI selectors.

Explanation:

When we want to use jQuery UI widget we have to code two things and these are the jQuery code and the jQuery UI selectors. jQuery UI is a managed set of user interface(UI) effects,interactions,themes and widgets built on top of  JavaScript jQuery Library.

So we have to code the jQuery and the jQuery UI selectors.

3 0
3 years ago
What is the missing line of code?
Ray Of Light [21]

Answer:

phrase[2:5]

Explanation:

Given:

The above code segment

Required

Which instruction returns 'u a'

First, we need to get the index of u in the phrase:

u is at the third position but in programming, index starts at 0.

So, u is at index 2

Next, we need to get the index of a in the phrase:

a is at index 4

One of the ways to return a sub string from a string in python is string[start:stop+1]

Where:

start = 2 ----- index of u

stop = 4  ----- index of a

phrase ---- The string variable

So, the instruction that returns 'u a' is: phrase[2:5]

<em>Where 5 = 4 + 1</em>

5 0
3 years ago
Other questions:
  • Terrance is working on a new document when he realizes that he would like to use a formatting system that he built in an old doc
    13·1 answer
  • What is nominal data?
    5·1 answer
  • Given the 32-bit binary number:
    13·1 answer
  • For what reasons do readers use text-to-speech tools? Check all that apply.
    8·2 answers
  • Which of the following is an advantage of computer usage? *
    10·1 answer
  • The transmission control protocol (TCP) layer helps computers to communicate in which of the following ways?
    10·1 answer
  • Before creating a graphic, you should _____. Select all that apply. A. export it as an SVG file B. consider whe
    12·1 answer
  • You can use the ____ method to search a string to determine whether it contains a specific sequence of characters.
    14·1 answer
  • True or false computers are an application of the on-off principle
    9·1 answer
  • What is the difference between the shares Folder and Sessions Folder in the Shared Folders tool?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!