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

i need help with this chart !

Answers

Not in high school but i tried my best to help

(Sorry that its blurry )

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

Explain the following term ( a) GUI ( b) WIMP


please give me the answer of this question

don't spam​

Answers

Explanation:

here you go mark my brainlist plzz

Gsjsbsjsgdbajavajabjabsusbsbbsbsbshshshs

Coal, nuclear and natural gas power plants all transform thermal energy into electricity
True
O False

Answers

True is the correct answer

Answer:

True

Explanation:

What is a decision tree

Answers

A decision tree is a diagram or chart that people use to determine a course of action or show a statistical probability.

Katie is a professional photographer. For a wedding season shoot, she chose an outdoor location to shoot her models wearing different kinds of
wedding gowns. She used natural lighting, and she kept the focus on the models with a blurry background. Which kind of focusing technique did
Katie use?

A- rack focus
B- silhouette focus
C- follow focus
D- selective focus

Answers

Answer:

D- selective focus

Explanation:

In photography the phrase 'selective focus' introduces a procedure where the photographer selectively concentrates on the subject of an illustration, basically neglecting all other characters of the scene.  The contrast of the intense subject toward the delicate image background formulates powerful, meditative images.

Answer:

Selective focus

Explanation:

can direct the viewers' attention to a subjectt by focusing on the subject and burring the background

Which is an example of how data is exported from a database?
A database is sorted and divided by subcategories.
A database imports data from a table.
A database object is saved using a file type that can be opened by other types of programs.
A database is saved under a new name.

Answers

Answer:

c

Explanation:

hope this helps

BJP4 Self-Check 7.21: swapPairs

plsssss

Answers

Answer:

needs more expiation

Explanation:

add a worksheet to the question

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 are the four different orchestral instrument families?
Name five string orchestral string instruments.
What are the most common brass instruments used in an orchestra?
Name four percussion instruments.
Name two different categories of orchestra.

HELP PLEASE

sorry btw i dont see a music subject

Answers

Answer:

Gutair

Violen

cello

Double Brass

Harp

Explanation:

I don’t really know can you explain more

What are the columns in a Microsoft Access table called?

Answers

Answer:

Field. In Access, columns are referred to as fields. When you organize your data by entering it into different fields, you are organizing it by type.


Which of the following types of networks covers a range of up to ten meters in distance?

Answers

Answer:

is there a pic

Explanation:

what is the correct java syntax to output the sentence: My dog's name is "dee-dee"?

Answers

Answer:

System.out.println("My dog's name is \"dee-dee\"");

Explanation:

You need to use the backslash to use quotes inside a string.

Which design element involves the act of lining up objects vertically or horizontally to give a sense of order?

Answers

Answer:

The answer is "Alignment".

Explanation:

The Alignment was its positioning of visual elements, such that they're coordinate together with such a structure. This is a layout concept that refers to words or pictures lining up with one page. They use coordination in the layout to coordinate entities, a system similar, equilibrium, framework formation, the connection among aspects, and clear and clear result.

The XBOX Live was NOT the best selling console of the 7th generation, but it was widely considered to be the most culturally influential.

Answers

this is true because the systematic design is basically the same with ten times better graphics

Do you have any sprites for Friday Night Funkin?

I am making mods and any sprites you have are fine. They just need to follow the idle rule and be appropriate :)

Answers

Answer:

id.k t

Explanation:

Nanotechnology is a scientific area that deals with making or changing things that are incredibly _______________.

Answers

Answer:

small

Explanation:

Nanotechnology deals with incredibly small things on the nanoscale.

The need to upgrade which component would likely lead to replacing the computer?

Answers

Answer:

CPU

Explanation:

The CPU is essentially the brain of a CAD system soooo

Write a letter to your friend explaining about the geographical confitions of Nepal's hilly region​

Answers

I don’t know your friend so you should be able to answer

Answer:

I don't know............

Part of the operating system core is responsible for controlling security, managing the file system, and providing a platform for applications to run on. What is this feature's name

Answers

Answer:

Kernel.

Explanation:

An operating system platform is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes.

This ultimately implies that, an operating system (OS) is essentially an interface between the computer’s hardware and all the software applications (programs) running on it.

Some examples of an operating system are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM, etc.

Kernel is part of the operating system core. It is responsible for controlling security, managing the file system, and providing a platform for applications to run on.

Basically, the kernel is the foundational or fundamental layer of the operating system (OS) and as such it is loaded into memory whenever the computer system starts to boot i.e the kernel must always reside in the memory of a computer because it is saddled with the responsibility of managing computer resources such as the central processing unit (CPU), peripheral devices, random access memory (RAM) and input/output instructions from software programs.

which type of scatter plot should the team use

A team wants to display two or three quantities related to the material properties. They also want to plot each quantity along an axis. They should use a/n _______ type of scatter plot for such material selection. ​

Answers

Answer:

Pretty sure it's matrix scatter plot

Explanation:

I got 4/5 on plato

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.

What is the next line?
>>> tupleB = (5.7.5.7.2.7)
>>> tupleB count(7)
2
1
0
3

Answers

Answer:

2

Explanation:

because

What are digital communication outlets?

Answers

Answer: Aps

Explanation: As consumers’ needs change, technology changes along with them, spurring the growth and evolution of digital communication platforms. In order to better utilize these platforms, it can be helpful to group them into categories.

What is the definition of overflow in binary?

Answers

Overflow occurs when the magnitude of a number exceeds the range allowed by the size of the bit field. The sum of two identically-signed numbers may very well exceed the range of the bit field of those two numbers, and so in this case overflow is a possibility.

help? brainliest and point

Answers

Answer: second one

Explanation:

sorry lol

What are some tasks for which you can use the VBA Editor? Check all that apply.


typing code to create a new macro

sharing a macro with another person

viewing the code that makes a macro work

starting and stopping the recording of a macro

modifying a macro to include an additional action

jk its a c e

Answers

Answer:

typing code to create a new macro

viewing the code that makes a macro work

modifying a macro to include an additional action

Explanation:

Typing code to create a new macro, viewing the code that makes a macro work and modifying a macro to include an additional action are some tasks for which you can use the VBA Editor. Hence, option A, C and D are correct.


What is Typing code?

In computer science and computer programming, a data type is a group of probable values and a set of allowed operations. By examining the data type, the compiler or interpreter can determine how the programmer plans to use the data.

If a variable is highly typed, it won't immediately change from one type to another. By automatically converting a string like "123" into the int 123, Perl allows for the usage of such a string in a numeric context. The opposite of weakly typed is this. Python won't work for this because it is a strongly typed language.

The symbol used to create the typecode for the array. the internal representation of the size in bytes of a single array item. Create a new element and give it the value.

Thus, option A, C and D are correct.

For more information about Typing code, click here:

https://brainly.com/question/11947128

#SPJ2

What should i get an RC cars or nerf guns Which should i get

Answers

Answer the nerf rc mounted cannon shooter

Explanation:

its a car with a mounted gun

Answer:

nerf gun

Explanation:

PLEASE MARK BRAINLIEST!!!!!!!!!!

5) Which one of the following tags is used to add caption to a table?
)
<table-caption> ii)
<tcaption>
<caption>​

Answers

Answer:

<caption></caption>

Explanation:

The other tags don't exist to my knowledge.

The tag that is used to add caption to a table is <caption>​. Check more about tags below.

What is the above tag about?

The <caption> tag is known to be a tag that tells more about the table caption. It is known to often defines it.

Conclusively, the use of the <caption> tag is one that need to be placed or inserted quickly  after the <table> tag is used.

Learn more about tags from

https://brainly.com/question/13153211

#SPJ2

Complete the code to finish this program to analyze the inventory for a store that sells purses and backpacks.

Each record is composed of the catalog number, the type of item, its color, the length, width, height, and the quantity in stock.

Sample rows of the file are bel[w.

234 purse,blue, 12,4,14,10

138,purse,red, 12.4.14,4

934, backpack, purple, 25,10,15,3

925, backpack,green 25,10,15,7

Answers

Answer:

import csv

fileIn = open("data/bags.txt","r")

countPurse = 0

textFile= csv.reader(fileIn)

for bag in textFile:    

   if bag[ 1 ] == 'purse':

       countPurse = countPurse + int(bag[6])

fileIn.close()

print("Number of purses:",countPurse)

Explanation:

I hope this helps!

Other Questions
why is america falling apart? Given the equation 25 + 7x = 11x = -2x = 2X = -14x = 14 Some equilateral triangles are not isosceles.O A. TrueO B. False If -3x + 5 > 4, which of the following cannot be a value of x? 7.11B-S) A -3 B -1 C D 4 solve each system by elimination.-20x - 16y = -2010x + 8y = 10 Shavon has a gift box shaped like a rectangular prism. The box is 12 inches long, 8 inches wide, and 3 inches high. What is the surface area if the gift box? A. 156 inB. 184 inC. 312 in D. 288 in ECha1) The smallest living unit is a the 2nd pic is question #1. if i made a mistake in that feel free to correct me Jorge walked 21/3 miles. Samuel walked 1/4 of the distant that Jorge walked how far did Samuel walk Need help on this please help Predictions about a story should be based onA. random choicesB. fantasiesC. desiresD. observations What were the effects of major new military technologies on World War I? I will give BRAINLIEST:) You have recently returned to live in your home country after being abroad for the last three years. Youfind that many things have changed.Now that you are home, write a letter to a friend.In your letter you should: describe how you are feeling now that you are back in your home country tell your friend about two or three things that have changed say what you plan to do now you are home. please helppppppDoes the equation 5(x 3) = 10x15 have one solution, infinitely many solutions, or no solution? 1) What is the capital of Chile? 6. The milk snake and the coral snake both have red, yellow, and black alternating stripes. In the milk snake, blackstripes separate bands of red and yellow. In the coral snake, yellow stripes separate black and red bands. Themilk snake is non-venomous, but the coral snake is highly venomous. How are these snakes an example ofcoevolution?The coral snake and the milk snake form a mutualistic symbiosis.* The coral snake and the milk snake have both evolved to eat the same types of prey.The coral snake is selectively favored by mimicking the non-venomous milk snake.The milk snake is selectively favored by mimicking the venomous coral snake. please help me on this will give you brainliest!! If tax rates decrease as income falls, the tax structure is Help please Read the following passage:"Eunsoo loved living in the dorm. Day or night, there were people to talk to and things going on. Sure, the dining hall food was awful,but that meant there was always someone happy to split a pizza or tag along on a snack run. Some of the other freshmen hated theconstant commotion, but it made her feel energized and alive."Which of the answers below is the best description of the cultural context of the reading?A- A girl parties a lot and never thinks of her studies.B- A college student binges on junk food and good times.C- An outgoing, friendly girl throws herself into the excitement of her first year in college. D- A young woman who doesn't like to be alone bonds with others over food.