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
Dione has created a PowerPoint presentation that has several common nouns, names of products, etc. He is
svetlana [45]

Answer:

D. Add

Explanation:

PowerPoint application can be defined as a software application or program designed and developed by Microsoft, to avail users the ability to create various slides containing textual and multimedia informations that can be used during a presentation. Some of the features available on Microsoft PowerPoint are narrations, transition effects, custom slideshows, animation effects, formatting options etc.

In this scenario, Dione has created a PowerPoint presentation that has several common nouns, names of products, etc. He is running Spell Checker and does not want to be notified in regard to these words in this presentation or in any other presentation created on this computer. Hence, the option he should choose is Add. This would be used to automatically add a list of all the common nouns.

3 0
2 years ago
Read 2 more answers
Computer has brought radical change in every field​
tigry1 [53]

Answer:

Yes it has brought change in every field

Explanation:

3 0
3 years ago
What is digital revolution?
oksano4ka [1.4K]
The Digital Revolution refers to the advancement of technology from analog electronic and mechanical devices to the digital technology available today. The era started to during the 1980s and is ongoing. ... The Digital Revolution is sometimes also called the Third Industrial Revolution.
5 0
3 years ago
Taking these steps will help to improve the delivery of your presentation.
NNADVOKAT [17]

Taking any/all of these steps will help to improve the delivery of your presentation:

<em>==> Be familiar with the place the presentation will be given.</em>

<em>==> Practice your presentation.</em>

<em>==> Move away from your computer frequently while speaking, and return to it to advance slides.</em>

<em>==> Use your conversation words and voice.  Don't read it from a paper (unless you can write in conversational words and phrases, but this is really hard to do).</em>

<em>==> Look around the audience while you're talking.  Make eye-contact with people. </em>

<em>==> Let your hands move normally while you talk.  Smile.</em>

-- Read from your slides so you don't forget your content.   ==> No. This is considered one of the signs of a poor presentation, and an inadequately prepared presenter.  

You're not there to read the slides to your audience.  They can read the slides just as well as you can.  You're there to explain, embellish, enhance, and enlarge the material on the slides.  If you don't have any more to tell them except what's on the slides, then you don't even need to drag yourself or the audience through the agony of the presentation. Just print the slides onto a handout, hand it out, dismiss the audience, and take the rest of the day off.  

Also, you're expected to know your subject well enough so that you don't need to read your slides to know what you're talking about, and to be well enough prepared to remember what comes next.

5 0
2 years ago
Read 2 more answers
The internet and the world wide web are the same thing <br> a. True <br> b. False
wariber [46]
Well its really both in a way but the answer is A) True 
4 0
3 years ago
Other questions:
  • In the Happy Valley School System, children are classified by age as follows: less than 2, ineligible 2, toddler 3-5, early chil
    6·1 answer
  • Which activity cannot be done on a social networking site?
    12·1 answer
  • 13. The Save As command is useful if you want to copy an open document and
    7·2 answers
  • Which is a feature of a strong thesis statement? A) It presents only the facts. B) It is open-ended. C) It answers the central q
    15·1 answer
  • What is x squared times b squared
    8·1 answer
  • Which criteria can cuboids/frame selectors be coloured by​
    15·1 answer
  • The design of a blog refers to:
    10·1 answer
  • Why is operating system important software for computer?give 3 reasons
    8·1 answer
  • Please help This is a homework in ICT class
    11·1 answer
  • What to do if you click on a phishing link on iphone
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!