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
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the t
Monica [59]

Answer:

int SmallestNumber(int num1, int num2, int num3){

int smallest;

if (num1 >num2){

smallest=num2;

}

else {

smallest=num1;

}

if(smallest <num3){

smallest=num3;

}

}

int LargestNumber(int num1, int num2, int num3){

int largest;

if (num1 <num2){

largest=num2;

}

else {

largest=num1;

}

if(largest>num3){

largest=num3;

}

}

void main(){

int num1,num2,num3;

printf("enter values");

scanf("%d%d%d",&num1,&num2,&num3);

int smallest=SmallestNumber(num1,num2,num3);

int largest=LargestNumber(num1,num2,num3);

}

Explanation:

we are comparing first two numbers and finding largest among those. After getting largest comparing that with remaining if it is greater then it will be largest of three. Same logic applicable to smallest also

7 0
3 years ago
What are the results of Maya’s conspicuous consumption? Check all that apply. - a lack of debt - stress about paying bills - a l
kifflom [539]

Answer:

stress about paying bills

a lack of money for other expenses

great electronic connectivity

Explanation:

The Maya classic period has seen the rise of conspicuous and mass consumption. In the given scenario all the expense her paid by credit cards and cash is rarely used. There will be a stress for paying bills. There will be lack of money available in hand for some routine expenses and mandatory purchases. It gives a great electronic connectivity. All the funds are considered as safe.

4 0
4 years ago
If a student passes off an authors work as his or her own, the student has
tatuchka [14]
Committed plagiarism, the student did not obtain permission to use the work, and the student said it was their original work.
7 0
4 years ago
Read 2 more answers
What term describes the story of a game?<br> tale<br> fable<br> narrative<br> setting
stiv31 [10]
I would say tale because a tales like more for stuff like games
8 0
2 years ago
Read 2 more answers
What can be the maximum possible length of an identifier 3163 79 can be of any length​
yawa3891 [41]

Answer:

79 characters

Explanation:

The programming language is not stated, but a little search online shows the question is about python programming language

Literally, identifiers are the names given to variables, arrays and functions.

In most programming languages (e.g. python), identifiers are case-sensitive.

i.e. Abc is a different identifier when compared to abc.

Having said that, python allows up to 79 characters to name an identifier.

Meaning that, the length of a variable name (or array, or function, etc.) can be up to 79 characters, and it cannot exceed 79 characters.

3 0
3 years ago
Other questions:
  • Consider a file system that uses inodes to represent files. Disk blocks are 8KB in size, and a pointer to a disk block requires
    12·1 answer
  • Pls help........
    15·1 answer
  • Whenever you communicate online, remember a. to delete anything you don't want to keep b. everything you put online is available
    13·1 answer
  • Write a routine to interchange the mth and nth elements of a singly-linked list. You may assume that the ranks m and n are passe
    10·1 answer
  • A person upgrades their computer's processor. The processor is responsible for 80% of the system's computing effort. What is the
    11·1 answer
  • Which of the following entries into the username and password fields will NOT cause us to gain admin access? You may assume that
    12·1 answer
  • For a parking application that lets you pay for parking via your phone, which of these is an example of a functional requirement
    8·1 answer
  • Consider Parameters with Referencing Environment. One complication with parameters that are subprograms appears only with langua
    11·1 answer
  • Write a java program as follows Write a method called powOfTwo that takes an integer as parameter, computes, and outputs it’s sq
    10·1 answer
  • an attacker uses the nslookup interactive mode to locate information on a domain name service (dns). what command should they ty
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!