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 statement will read an entire line of input into the following string object?
Solnce55 [7]

Answer:

getline(cin, address);

Explanation:

Given

String object: address

Required

Statement that reads the entire line

The list of given options shows that the programming language is c++.

Analysing each option (a) to (e):

a. cin<<address;

The above instruction will read the string object until the first blank space.

Take for instance:

The user supplied "Lagos state" as input, only "Lagos" will be saved in address using this option.

b. cin address:

This is an incorrect syntax

c. getline(cin,address);

Using the same instance as (a) above, this reads the complete line and "Lagos state" will be saved in variable address

d. cin.get(address);

address is created as a string object and the above instruction will only work for character pointers (i.e. char*)

<em>From the above analysis, option (c) is correct.</em>

6 0
3 years ago
The responsibilities of the IT department and the needs of the user departments may cause conflicts over A. the color of the use
monitta

I'd say B: the amount and type of security placed on an application.

This is a common problem that exists between IT and other user departments. The IT department is well known for closing up certain sites and applications needed by other departments all in the name of security. As a result, it might slow down operations within different department and may cause inefficiency.

4 0
4 years ago
If you enjoy exploring,"what would happen if"types of questions and activities,a career in science or technology might be a good
zhannawk [14.2K]

Answer:

option (a)

Explanation:

Computer science provides millions of ways in which we can code different types of scenarios and options we can imagine. Any scenario or problem can be thought to solve using programming. So there can be thousands of ways of exploring the paths never explored. Lots of ways to counter any situation and think what if i could change this condition to another and what solution would come up.

5 0
3 years ago
Plsss 30 points!!!!
Elanso [62]

Answer:

a

Explanation:

4 0
3 years ago
What is the relationship between optical drives and WORMs?
Effectus [21]

Answer:

When data is written to a WORM drive, physical marks are made on the media surface by a low-powered laser and since these marks are permanent, they cannot be erased. Rewritable, or erasable, optical disk drives followed, providing the same high capacities as those provided by WORM or CD-ROM devices.

Explanation:

Good luck

6 0
3 years ago
Other questions:
  • A company that manufactures machine parts order a new system that makes Products at ten times the speed of earlier machines. the
    13·2 answers
  • The command to delete all the files that have filenames that starts with letter c or c and ends with a letter z or z is
    15·1 answer
  • Are the actions legal or illegal?
    13·1 answer
  • What statement should you use to print the value of total with a precision of 5 digits?
    7·1 answer
  • Which of the following does not represent the function of a Variable? Variables store data in memory; this data has limited use
    8·1 answer
  • I have a computer teacher who made me lose points in an assignment and saying that the reference page should be on a separate pa
    14·1 answer
  • Công dụng của đồng hồ đo điện:vôn kế, ampe kế, oát kế
    15·1 answer
  • 70 point Brainlist to best answer
    15·1 answer
  • The RGB value below produces a shade of purple. What does the number 175
    15·2 answers
  • You have implemented an access control method that only allows users who are managers to access specific data. Which type of acc
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!