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
Identify the most appropriate way to display the following research data.
VMariaS [17]

Answer:

1. Artwork of the child participants can be displayed as Picture.

Explanation:

The Art work is painting and filling different colors in different images and objects. Child make different pictures of homes, objects, fruits and vegetables and then colored them accordingly. This type of art work is displayed as picture. This work could not be displayed in the form of tables and lists and also could not shown as graphics.

Answer:

2. The changing image of public transportation is displayed as Graphics.

Explanation:

In Graphics, different images has been designed on different tools by graphic designers to display some problem and its solution in visuals. Different tools are there to make visuals. Changing image of bus transportation is also a transition from old transport system to new transportation system. So, it should displayed in the form of graphics.

Answer:

Illustrative comparison of data from the year 2010-2013 can be displayed in the form of word tables and lists.

Explanation:

In tables and list different data has been placed in specific order for the purpose of analysis of data. These tables are also designed to compare different values and things. So, the data from the year 2010-2013 can be displayed in the form of tables and list so that it can be compared and analyze from different aspects.

7 0
3 years ago
What is the difference between posting and transfer in ICT please I need the answer before TMR​
Radda [10]

Answer: b

Explanation: trust

7 0
2 years ago
A pointing device used mainly for computer games is known as
kolbaska11 [484]

Answer: Joystick is the only one that makes sense, a stylus and digitizer are both used on drawing tablets, not computer games.

5 0
2 years ago
How do I write this code in java? input "Enter Your Age to Order a Beer"
Klio2033 [76]

Answer:

i dont know sorry but answer above lol

Explanation:

5 0
3 years ago
What some one ask me if i am more of hardware or software person, what is that mean?
balu736 [363]

Answer: Any person or people asking about someone being a hardware or software person displays that they are questioning about the computer knowledge of the person and his/her interest.

The interest can be regarding software tools for programming, designing ,  etc or hardware device like troubleshooting, assembling the computer parts ,etc.

The person persisting good knowledge about software programming language and software is diverted towards software side .The person who likes to deal with hardware parts of the computer system is hardware-oriented person.

7 0
3 years ago
Other questions:
  • The manager of a sports club has data about the club members' ages in a workbook. He wants to find which age is most common. Whi
    13·2 answers
  • What is a step by step procedure written to carry out a task?
    11·1 answer
  • If an M/M/1 queue in a server has task arrivals at a rate of 30 per second and serves at a rate of 50 per second, how many tasks
    10·1 answer
  • What is the name of the popular DBMS (database management system) that is open source and is distributed under the General Publi
    15·1 answer
  • What is the color difference between the iMac and iMac Pro
    14·2 answers
  • How can i turn on my prinfer without getting up
    12·2 answers
  • The _____ feature will mark all changes made to a document for others to review at a later time.
    13·1 answer
  • 7.5 Code practice Plz answer ASAP
    15·1 answer
  • There are parallels between the trust models in Kerberos and Public Key Infrastructure (PKI). When we compare them side by side,
    15·1 answer
  • HELP ME?!!?!?!?!?!?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!