Write a program to declare a matrix A[][] of order (MXN) where ‘M’ is the number of rows and ‘N’ is the
number of columns such M and N must be
greater than w and less than 20. Allow the user to input





integers into this matrix. Perform the following tasks on the matrix:
(a) Display the input matrix
(b) Find the maximum and minimum value in the matrix and display them along with their position.
(c) Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix.

Can anybody show the program and explain please
Urgent.

Answers

Answer 1

Answer:

import java.io.*;

import java.util.Arrays;

class Main {

   public static void main(String args[])

   throws IOException{

       // Set up keyboard input

       InputStreamReader in = new InputStreamReader(System.in);

       BufferedReader br = new BufferedReader(in);

 

       // Prompt for dimensions MxN of the matrix

       System.out.print("M = ");

       int m = Integer.parseInt(br.readLine());

       System.out.print("N = ");

       int n = Integer.parseInt(br.readLine());

       // Check if input is within bounds, exit if not

       if(m <= 2 || m >= 10 || n <= 2 || n >= 10){

           System.out.println("Matrix size out of range.");

           return;

       }

       // Declare the matrix as two-dimensional int array

       int a[][] = new int[m][n];

 

       // Prompt for values of the matrix elements

       System.out.println("Enter elements of matrix:");

       for(int i = 0; i < m; i++){

           for(int j = 0; j < n; j++){

               a[i][j] = Integer.parseInt(br.readLine());

           }

       }

       // Output the original matrix

       System.out.println("Original Matrix:");

       printMatrix(a);

       // Sort each row

       for(int i = 0; i < m; i++){

         Arrays.sort(a[i]);

       }

       // Print sorted matrix

       System.out.println("Matrix after sorting rows:");

       printMatrix(a);

   }

   // Print the matrix elements separated by tabs

   public static void printMatrix(int[][] a) {

       for(int i = 0; i < a.length; i++){

           for(int j = 0; j < a[i].length; j++)

               System.out.print(a[i][j] + "\t");

           System.out.println();

       }

   }

}

Explanation:

I fixed the mistake in the original code and put comments in to describe each section. The mistake was that the entire matrix was sorted, while only the individual rows needed to be sorted. This even simplifies the program. I also factored out a printMatrix() method because it is used twice.


Related Questions


True or False
the short key to insert a new slide is Ctrl + N key combinatio​

Answers

Answer:

True

Explanation:

Ctrl + N = Create new document, window, workbook, or other type of file.

A color channel is a layer of the image seen through one particular color only. This color channel appears in the image-editing software in grayscale. How would you identify which parts of the image have the highest saturation of that particular color and which parts have the least saturation?

When viewing an image in a single channel in an image-editing software, the [blank] of the image contain the least or no amount of the color of that channel. You can see the most amount of color of that channel in the [blank] of the image.


drop box options:

lighter tones

darker tones

white areas

Answers

Answer:

Lighter tones

Darker tones

Explanation:

The color channel stream in the computer is the combination of primary colors which gives the image look colorful. The saturation turns the image red  and the contrast gives brighter colors to the image. The image is turned towards lighter tones with the highlights effect through editing software.

Which of these statements correctly describe aspects of testing code? Check all of the boxes that apply.

Users depend on the information provided by the software program.

Beta testing is the second stage of testing the software program.

All testing is done by the developer of the computer software.

All code is likely to include mistakes, no matter how careful a programmer may be.

Answers

Answer:

1 - Users depend on the information provided by the software program.

2 - Beta testing is the second stage of testing the software program.

4 - All code is likely to include mistakes, no matter how careful a programmer may be.

Explanation:

ON EDGE TRUST

plz mark brainest

IT IS THE FIRST ONE AND THE THIRD ONE

Explanation:

i just did it

What is the value of creating recurring tasks?

makes task reminders more noticeable
makes task reminders more efficient
saves time spent manually creating multiple tasks
saves time spent manually configuring recurrence settings

Answers

Answer:

✔️saves time spent manually creating multiple tasks

Explanation:

I did it on edge

Answer:

saves time spent manually creating multiple tasks

Explanation:

it correct on edge 2021

Huzaifa is a grade 5 student who is very enthusiastic to learn coding in computers. He asks his computer teacher to help him choose a language to code. Which level language will the teacher recommend Huzaifa?

Answers

Answer:

High level language.

Explanation:

High level language can be defined as a programming language which is generally less complex than a machine (low level) language and easy to understand by the end users (programmers).

This ultimately implies that, a high level programming language is typically a user friendly language and as such simplifies coding or programming for beginners.

Some examples of high level programming language are Python, Java, C#, Ruby, Perl, Visual Basic, PHP, Cobol, C++, Fortran, Javascript, etc.

In this scenario, Huzaifa is a grade 5 student who is very enthusiastic to learn coding in computers. He asks his computer teacher to help him choose a language to code. Thus, the language level the teacher will recommend to Huzaifa is a high level language.

A Hospital wants to store different types of data I need to find the best storage device for each type and why what is the best storage device to store the patient's data

Answers

Answer:

On-Premise Data storage

Explanation:

On-Premise Data storage prefers on-premise data to store and manage patient data. The main reason is straightforward and control over the in-house data. On-premise data centers do not need wireless connections, and no risk of downtimes. Healthcare can access the data from secure, making on-premise data storage choices.

On-premise data storage stored and managed escalates and demand more physical space. When hospitals use on-premise data storage, they have to arrange the physical space within the premises of the host of the server.  On-premise data is connected to the local network and could consider the secure data option in upkeeping the security of premise healthcare with anti-virus software, firewalls, and multifactor authentication.

Hospital moves toward holistic data storage option. The on-premise to cloud data storage for healthcare affirms that challenges are nullified.

3. One advantage of online classrooms over physical classrooms is that:
A-You can usually take the classes on your own time.
B-It is easier to access class materials.
C-You can communicate with your teacher more effectively.

D-The quality of the teaching is usually better.


Answers

Answer:

c

Explanation:

You can communicate your teachers

Which of the following statements best describes the relative amount of content held by digital libraries vs. the amount held by traditional libraries?

Digital libraries have more access to fiction, while traditional libraries have more access to nonfiction and reference materials.

Traditional libraries tend to have access to more information because they have been around longer.

Digital libraries and traditional libraries both tend to have the same access to information.

Digital libraries tend to have access to more information because they can share with other digital libraries.

Answers

Answer:

Digital libraries tend to have access to more information because they can share with other digital libraries.

Explanation:

A digital library can be defined as an electronic or cloud-based library where informations and books about various things, places, people, animals, subjects, etc, are kept for readers to access over the internet.

On the other hand, a traditional library is a physical library that people can walk into to read.

The statement which best describes the relative amount of content held by digital libraries vs. the amount held by traditional libraries is that, digital libraries tend to have access to more information because they can share with other digital libraries because they are usually interconnected through network.

What happens when a user clicks Accept on a meeting request?

Other events at that time are canceled, and the meeting cannot be canceled by the organizer.
The agenda is updated with the user’s contact information, and other events at that time are canceled.
The meeting cannot be canceled by the organizer, and the agenda is updated with the user’s contact information.
The meeting organizer is notified, and a copy of the meeting is added to the user’s Outlook calendar.

Answers

Explanation:

Other events at that time are canceled, and the meeting cannot be canceled by the organizer.

The agenda is updated with the user’s contact information, and other events at that time are canceled.

The meeting cannot be canceled by the organizer, and the agenda is updated with the user’s contact information.

The meeting organizer is notified, and a copy of the meeting is added to the user’s Outlook calendar.

Answer:

the last one

Explanation:

just did it

What is a working model used to test a design called?

Answers

A working model used to test a design is a prototype.

Answer:

mockup is the working model

Which option is not a default when adding voting buttons to an outgoing message?

Approve:Reject
Yes:No
Custom
True:False

Answers

Custom option is not a default when adding voting buttons to an outgoing message. Hence option c is correct.

What is message?

Message is defined as a specific communication unit that the source intends for some recipient or set of receivers to consume.  A broadcast's content could be a message. The information being conveyed during communication is known as the message. Sender and recipient are linked by the message.

Create an email message, respond to one you've already received, or forward it. Click Use Voting Buttons under the Tracking group on the Options tab. Please click Options > Use Voting Buttons > Custom when you are back in the message window.  Please enter your preferred voting methods in the Use voting buttons box in the Properties dialogue box before clicking the Close button.

Thus, custom option is not a default when adding voting buttons to an outgoing message. Hence option c is correct.

To learn more about message, refer to the link below:

https://brainly.com/question/28529665

#SPJ2

Which is the hanging indent on the rulern

Answers

Answer:

indent is a space between the red line.

Explanation:

Which of the following could be an example of a type of graphic organizer about jungle animals

A. A collection of photos with links to audio files of noises made by jungle animals

B. A paragraph describing different jungle animals

C. A picture of one jungle animal with no caption

D. A first person narrative about a safari

Answers

B) A paragraph describing different jungle animals

Answer:it’s a collection of photos with links blah blah blah

Explanation:just took it other guy is wrong

What would be a suitable device to transfer 12 photos from one PC to another?

Answers

Answer:

A memory stick.

Explanation:

A memory stick can be defined as a storage media device with flash memory. They are mainly used in smart or portable electronic devices such as mobile phones, digital cameras, mp3 players, camcorders, etc.

Memory sticks are usually small in size and as such are easily accessible for the transfer of digital files such as images, videos, audios from a portable device or computer to another device such as a computer.

Hence, a memory stick would be a suitable device to transfer 12 photos from one PC to another.

A robot as a barista or Not?

Answers

Answer:

robot barista

Explanation:

Yay so it doesn’t take 5 years for my coffee to be made

Bonjour ma question est: expliquer comment fonctionne une calculatrice qui ne contient pas une pile. Pouvez-vous m'aider?

Answers

Answer:

Tout calculateur électronique ou numérique nécessite une source d'alimentation pour fonctionner, avec son circuit configuré à la porte logique requise liée aux touches d'entrée et à l'écran de sortie.

Explanation:

Les calculatrices sont des appareils utilisés pour les calculs arithmétiques. Au 19ème siècle, les calculatrices étaient mécaniques et n'utilisaient pas de batterie, elles étaient encombrantes et utilisaient des tiges et des engrenages dans leur fonctionnement. Les calculatrices récentes sont électroniques, alimentées par une batterie. Ils comprennent un circuit électronique configuré à sa porte logique requise pour le calcul, un bouton pour l'entrée et un écran pour la sortie du calcul.

In the space below, list two or three of the basic classes of application software.

Answers

Answer:

business (database, accounting, analysis)

communications (e-mail, word processing)

entertainment (games, music, videos)

science and engineering (computer-assisted design or CAD, statistics)

development (software to make software)

emerging classes (robotics, translation)

Explanation:

The basic classes of application software that can be listed are as follows:

For business - database, accounting, analysis

For communications - email, word processing

For entertainment -  games, music, videos

Hence, these are the basic classes of application software.

What is an application software?

On a computer, there are many kinds of software that are needed by a person so that they can perform tasks easily and smoothly. The term "application software" is used to denote the kind of computer programme which is used to perform a specific kind of task or function by any individual.

It can be at a personal level, an educational level, or a business level. Whenever a person purchases any system, be it a computer or a laptop, the application software that is used by that person is also purchased.

This is dependent on their profession or the requirement, which is to be a full-flight software which is present in the world for easy and smooth working of day-to-day individuals.

Thus, some of the application software are business, communications, entertainment, development, and many more.

Learn more about application software from here:

https://brainly.com/question/14612162

#SPJ2

Other Questions
Read the excerpt from On Womens Right to Vote, an 1873 speech by Susan B. Anthony.It was we, the people; not we, the white male citizens; nor yet we, the male citizens; but we, the whole people, who formed the Union. And we formed it, not to give the blessings of liberty, but to secure them; not to the half of ourselves and the half of our posterity, but to the whole peoplewomen as well as men.Which quotation correctly uses ellipsis to shorten Anthonys words?It was we, the people . . . the whole people, who formed the Union. And we formed it, not to give the blessings of liberty, but to secure them; not to the half of ourselves and the half of our posterity, but to the whole peoplewomen as well as men.It was we, the people . . . not we, the white male citizens; nor yet we, the male citizens; but we, the whole people, who formed the Union. And we formed it, not to give the blessings of liberty, but to secure them; not to the half of ourselves and the half of our posterity . . . .It was we . . . the male citizens; but we, the whole people, who formed the Union. And we formed it, not to give the blessings of liberty, but to secure them; not to the half of ourselves and the half of our posterity, but to the whole peoplewomen as well as men.It was we, the people; not we, the white male citizens; nor yet we, the male citizens; but we, the whole people, who formed the Union. And we formed it, not to give the blessings of liberty . . . to the whole peoplewomen as well as men. Determine the permanent life insurance amount per thousand given that the policy belongs to a healthy 25-year-oldmale with an annual premium of $4,072.2 and a face value of $110,000 on a 20-Year Endowment insurance policya $38.96$37 67b. $38.23di $37.02C A field is a rectangle with a perimeter of 1240 feet. The length is 400 feet more than the width. Find the width and length of the rectangular field.The width Add the integers.-6 + (-4) =( ?B-2C 2D 10 Help please! Thank you!!!!!!!!!!!!!!!!! Let's say a student scored 33 on a math achievement test for which scores are normally distributed with mean43 and standard deviation 10. What proportion of students finished worse than her? A department store buys 300 shirts at a cost of $3,600 and sells them at a selling price of $20 each. Find the percent markup. The percent markup is 1%. (Round to the nearest whole number as needed) Solve the inequality: y - 18 < 55 In the text box, write the next 3 terms in the sequence and describe the pattern. In the checkbox, identify if the sequence is arithmetic, geometric or neither and identify if the sequence has a common ratio, a common difference or neither.-4, -2, 0, 2, ____, ____, ____,ArithmeticGeometricNeitherCommon differenceCommon ratio The third assignment involves writing a Python program to compute the cost of carpeting a room. Your program should prompt the user for the width and length in feet of the room and the quality of carpet to be used. A choice between three grades of carpeting should be given. You should decide on the price per square foot of the three grades on carpet. Your program must include a function that accepts the length, width, and carpet quality as parameters and returns the cost of carpeting that room. After calling that function, your program should then output the carpeting cost.Your program should include the pseudocode used for your design in the comments. Document the values you chose for the prices per square foot of the three grades of carpet in your comments as well.You are to submit your Python program as a text file (.txt) file. In addition, you are also to submit a test plan in a Word document or a .pdf file. 15% of your grade will be based on whether the comments in your program include the pseudocode and define the values of your constants, 70% on whether your program executes correctly on all test cases and 15% on the completeness of your test report. Indicate below whether the equation in the box is true or false.4/8 = to 6/10 Which describes the relationship between: QVP and PVU? Please helpppppppppppppCundo comes estas comidas?When do you eat these foods?Write your answers in Spanish1. Arroz con pollo ________2. Frutas___________3. Cereal con leche y tostadas __________4. Hamburguesas_____________5. Pescado____________6. Ensalada_____________ Describe how you know whether an equation will be true for all values of x or true for no values of x. Which fact about the tenochitian peoples can be found in both passages the end of Aztec empire and moctezuma II Although this has slowed a little bit in the last few years, since the beginning of the 21st century, the fastest growing market for oil in the world has been: Need help with math points and brainlest Do you think it is ever okay to remove animals from the wild and bring them into captivity? Why or why not? whats the balance to Sr + O, SrO Who has legislative power in the federal government?