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
What is the purpose of flight simulator programs, and what are some of the benefits of using them?
saw5 [17]

Answer:

Flight simulators provide a cost-effective way for pilots to practice both routine and rarely-used skills. With simulator training, you can refine your skills in a variety of different flight scenarios that can be tailored to your specific goals.

Explanation:

hope this helps <3

6 0
2 years ago
Read 2 more answers
Text that is heavier or darker than other text in the document is considered _____.
kvv77 [185]

The text that is heavier or darker than other text in a document is considered  Bold.

Hope this helped!~

7 0
3 years ago
Read 2 more answers
Jim is in the market for a car that will last for the next 10 years and has saved up some money for the purpose of a car. What’s
Ratling [72]
I would imagine car would still be the best means , it's tough to define without knowing where he lives and how much he travels
8 0
3 years ago
Protocols used in each layers in each osi reference model
natka813 [3]

The protocols  that are often used in each layers in each OSI reference model are:

Layers                           Protocols

Layer 7- Application          SMTP, HTTP, FTP, POP3, SNMP

Layer 6- Presentation           MPEG, ASCH, SSL, TLS

Layer 5-Session                   NetBIOS, SAP

Layer 4-Transport                      TCP, UDP

Layer 3-Network                IPV5, IPV6, ICMP, IPSEC, ARP, MPLS.

Layer 2-Data Link       RAPA, PPP, Frame Relay, ATM, Fiber Cable.

Layer 1-Physical              RS232, 100BaseTX, ISDN, 11.

<h3>What is OSI Model?</h3>

The OSI Model is known to be a kind of a logical and conceptual framework that tells all about network communication that is often used by systems in an open to interconnection and also in any communication with other forms of systems.

Note that the Open System Interconnection (OSI Model) is one that tells more about a logical network and it is one that also tells about computer packet transfer via the use of various layers of protocols.

Therefore, The protocols  that are often used in each layers in each OSI reference model are:

Layers                           Protocols

Layer 7- Application          SMTP, HTTP, FTP, POP3, SNMP

Layer 6- Presentation            MPEG, ASCH, SSL, TLS

Layer 5-Session                   NetBIOS, SAP

Layer 4-Transport                      TCP, UDP

Layer 3-Network                IPV5, IPV6, ICMP, IPSEC, ARP, MPLS.

Layer 2-Data Link       RAPA, PPP, Frame Relay, ATM, Fiber Cable.

Layer 1-Physical              RS232, 100BaseTX, ISDN, 11.

Learn more about OSI reference model  from

brainly.com/question/12976859

#SPJ1

8 0
1 year ago
One example of how psychological research can be used to control harmful behavior would be __________. A. fooling individuals th
Sati [7]

The results of a psychological research can be used for malignant purposes, such as fooling individuals through their emotions, using propaganda to change beliefs, and manipulating others through the media.

But it can also be used for good – which is what the question is asking. It is clear that from the available options, only (D) improving communication and relationships are an example of how psychological research is used for good.

8 0
3 years ago
Read 2 more answers
Other questions:
  • How to write "There are four parking spots on campus that may be used only by Nobel Prize winning faculty." this sentence correc
    12·1 answer
  • Which of these is a social consequence of effective communication
    12·1 answer
  • 1). What is the proper name of the healing agent?
    5·1 answer
  • What is the output of the following function if the array nums contains the values 1 2 3 4 5 int backwards(int nums[]) { for (x
    15·1 answer
  • The accounting department moved its network-attached printer from one side of the office to a more centralized location, making
    11·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    13·1 answer
  • Which object event is an indication that something has been created but not committed into the database?
    13·1 answer
  • How do u delete a post on brainly
    7·1 answer
  • A good algorithm should have which three components?
    6·1 answer
  • What kind of AR target category makes sense for a playing card with a picture on it?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!