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
Stella [2.4K]
3 years ago
10

Write a program in java to find the maximum values in each row and column of a two-dimensional array of integers read from the u

ser. First ask the user for the number of rows and columns, then allocate the two-dimensional array of that size. Next read from the user each row of values, store them then output the maximum values for each row (horizontal) and column (vertical). can some one please help me in this program. in java Sample 1 (user inputs are shown in bold italics) How many rows? 5 How many columns? 4 Enter the values of row 0 separated by spaces 52 68 62 75 Enter the values of row 1 separated by spaces 88 52 -84 -68 Enter the values of row 2 separated by spaces -24 51 -67 82 Enter the values of row 3 separated by spaces 14 78 61 97 Enter the values of row 4 separated by spaces 67 -11 4 47 Results: 52 68 62 75 [75] 88 52 -84 -68 [88] -24 51 -67 82 [82] 14 78 61 97 [97] 67 -11 4 47 [67] [88] [78] [62] [97]
Computers and Technology
1 answer:
MaRussiya [10]3 years ago
5 0

Answer:

//here is code in Java.

import java.util.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

try{

// variable to store row and column size

int row_size,col_size;

Scanner inp=new Scanner(System.in);

System.out.print("How many rows?");

// read the row size

row_size=inp.nextInt();

System.out.print("How many columns?");

//read the column size

col_size=inp.nextInt();

// create an array of size rowxcolumn

int[][] mat=new int[row_size][col_size];

// array to store row max and column max

int max_of_row[]=new int[row_size];

int max_of_col[]=new int[col_size];

// read the elements of array

for(int x=0;x<row_size;x++)

{

int m=Integer.MIN_VALUE;

System.out.println("enter elements of row "+x+" separated by spaces:");

for(int y=0;y<col_size;y++)

{

// find the maximum of each row

mat[x][y]=inp.nextInt();

if(mat[x][y]>m)

m=mat[x][y];

}

max_of_row[x]=m;

}

// print the output in required format

System.out.println("Results:");

for(int a=0;a<row_size;a++)

{

for(int b=0;b<col_size;b++)

{

System.out.print(mat[a][b]+" ");

}

System.out.print("["+max_of_row[a]+"]");

System.out.println();

}

// find the maximum of each column

for(int x=0;x<col_size;x++)

{

int max_c =Integer.MIN_VALUE;

for(int y=0;y<row_size;y++)

{

if(mat[y][x]>max_c)

{

max_c=mat[y][x];

}

max_of_col[x]=max_c;

}

}

// print the max of each column

System.out.println("max of each col:");

for(int a=0;a<col_size;a++)

{

System.out.print("["+max_of_col[a]+"]"+" ");

}

}catch(Exception ex){

return;}

}

}

Explanation:

Read the number of row and column. Create an array of size rowxcolumn. Read the elements of the array and find the max of each row. Save the max of each row in an array. Find the max of each column and save it in another array.Print the required output.

Output:

How many rows?5                                                                                                                

How many columns?4                                                                                                              

enter elements of row 0 separated by spaces:                                                                                

52 68 62 75                                                                                                                    

enter elements of row 1 separated by spaces:                                                                                

88 52 -84 -68                                                                                                                  

enter elements of row 2 separated by spaces:                                                                                

-24 51 -67 82                                                                                                                  

enter elements of row 3 separated by spaces:                                                                                

14 78 61 97                                                                                                                    

enter elements of row 4 separated by spaces:                                                                                

67 -11 4 47                                                                                                                    

Results:                                                                                                                        

52 68 62 75 [75]                                                                                                                

88 52 -84 -68 [88]                                                                                                              

-24 51 -67 82 [82]                                                                                                              

14 78 61 97 [97]                                                                                                                

67 -11 4 47 [67]                                                                                                                

max of each col:                                                                                                                

[88] [78] [62] [97]

You might be interested in
Students at a university are working on a project. The project involves many computing systems working together on disjointed ta
vitfil [10]
I think that C. cloud computing sounds like the best answer.
7 0
3 years ago
Read 2 more answers
The _____ displays numbers with a fixed dollar sign to the left of the number, a comma every three positions to the left of the
slava [35]

Answer: the accounting number format

Explanation:

The standard accounting number format usually contains a dollar sign, a thousands separator and two decimal points, the dollar sign is locked to the far left side of the cell in an enclosure.

How to apply the accounting number format ;

I, select the range and right-click and choose Format Cells.

Ii. In the Format Cells Dialog box, with the Number Tab selected, choose Accounting

Iii. Accept the options shown below and click Ok.

The Accounting Format has been applied.

4 0
3 years ago
If my 98 dodge ram 1500 truck is dropping RPM's when i stop does that mean i need new throttle body sensors or does it mean i ne
geniusboy [140]
You might need a new 02 sensor and i really dont know about the vacuum leak.
6 0
3 years ago
Read 2 more answers
What can you do to make sure no one outside your company can gain access to its wireless network?
Oksana_A [137]

Disable SSID broadcasting, Lower radio energy groups, and Enable MAC filtering.

<h3>Why would you disable SSID broadcasting?</h3>
  • Disabling the SSID Broadcast is one method of ensuring your wireless web.
  • This procedure will stop other users from detecting your SSID or your wireless network title when they attempt to view the available wireless networks in your area.
  • The network character exists delivered to wireless devices, which is the reason for disabling the SSID broadcast.
  • A typical wireless adapter and its associated software will identify and list all available SSIDs for networks that are within range.
  • When somebody disables SSID broadcast on any of those networks, the network will no extended show up in the wireless adapter's list of known networks.

To learn more about Disable SSID broadcasting, refer to:

brainly.com/question/15289342

#SPJ4

The complete question is:

Your company shares a building with a competitor's branch office. Recently, you noticed that some computers other than company computer have tried to connect to the wireless network unsuccessfully. When you are in the parking lot, you also notice that the company's wireless network SSID can be seen on your smartphone.

What can you do to make sure no one outside your company can gain access to its wireless network?

6 0
2 years ago
Why are cable networks such as mtv and cnn more profitable than the big four broadcast networks?
aalyn [17]
<span>Cable television was developed to deliver broadcast television signals to communities with poor reception.
</span><span>Cable networks such as MTV and CNN are more profitable than the big four broadcast networks because </span>viewers pay for subscriptions and companies pay for advertising. Viewer pay monthly fee for viewing cable TV and companies pay in order their campaign to be broadcasted.
8 0
4 years ago
Other questions:
  • printStars is a method that accepts a single int argument and returns no value. It prints as many stars as indicated by its argu
    9·1 answer
  • Which of the following is true? A)Checks and Debit Cards both withdraw money directly from a bank account. B)Checks are the most
    13·2 answers
  • The jaws of ________ chucks are advanced and retracted independently of each other and allow for fine-tuning the position of the
    6·1 answer
  • A potential threat to administrators’ ability to manage the correctional system is
    12·1 answer
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    11·1 answer
  • How many occupational groups are there in the SOC system?
    12·1 answer
  • If you are interested in working for a specific company, what type of job site should you look at for opening?
    15·2 answers
  • Create a class template for a class named GeneralStackthat holds
    8·1 answer
  • Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers
    14·1 answer
  • _______________ provides options for getting access to your old password or resetting the account to a temporary password; users
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!