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
You are having trouble cleaning your computer for a troublesome virus. you decide to try to clean your computer while in safe mo
navik [9.2K]
If I am not mistaken, you either press the f5 button before the computer posts or the f8 button before it posts. My old Toshiba showed what button to press. You then use the arrow keys to maneuver to OPEN SAFE MODE. I am not sure if my old computer is the same or close to yours, but just try it yourself on your computer. No permanent damage will be done. If you are stuck, just go back to REBOOT COMPUTER
8 0
4 years ago
Jason is computer professional who has access to sensitive information. He shares this information with another organization in
Verdich [7]
C will be your answer.
8 0
3 years ago
Read 2 more answers
Software that tries to monitor and track the way you use your computer.​
Lostsunrise [7]

Explanation:

that's called a virus, and it can do much harm to your softwares

5 0
3 years ago
Read 2 more answers
Which option will enable Mina to apply several formats to the spreadsheet cells at the same time? A. cell content B. cell patter
Gemiola [76]

The correct answer is Cell Style.

In order for Mina to apply several formats at the same time she should use the cell style option. When using styles you can apply multiple formats at the same time. You can do this for any amount of cells, from one to the entire workbook.

8 0
3 years ago
The main benefit of shielded twisted pair cabling over unshielded twisted pair is that STP is much more durable.
Likurg_2 [28]

Answer: True

Explanation:

In shielded twisted pair (STP) we have two wires which are twisted together and they have a shielding layer outside them which helps them to avoid interference from outside noise. STP thus having the advantage with an additional layer of shield covering the two wires together makes them more durable compared to unshielded twisted pair.

7 0
4 years ago
Other questions:
  • Which of the following would indicate that a website is a secure site?
    7·2 answers
  • PLEASE HELP
    9·2 answers
  • What version of android did nexus one run?
    14·1 answer
  • Write a function "cashier" that receives an int "c" for the number of items bought. The function will ask the price and task rat
    11·1 answer
  • Which of the following statements best reflects the usefulness of commercial digital editing programs?
    7·1 answer
  • How do you launch windows on a computer?
    14·1 answer
  • Write a Java Program that can compute the mean, median, the highest, and the lowest of the students’ scores in a class. First, t
    6·1 answer
  • When adding shapes to a presentation, the outline can be one color, and the fill must be the exact same color.
    12·2 answers
  • In the program below, numA is a _____.
    8·2 answers
  • Choose all items that represent features of the job application process.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!