answer.
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
patriot [66]
2 years ago
8

Write a program to declare a matrix A[][] of order (MXN) where ‘M’ is the number of rows and ‘N’ is the

Computers and Technology
1 answer:
Liula [17]2 years ago
4 0

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.

You might be interested in
The ________ utility automatically creates duplicates of your libraries, desktops, contacts, and favorites to another storage lo
olga55 [171]

Answer:

The correct answer for the given question is option(A) i.e File History.

Explanation:

In computer system file history is an backup application which create backup of your data which are stored in your libraries, desktops, contacts, and favorites to another storage location .It creates back up of your data  to another location when your personal files has been changed.

The user can check the file history option in computer system

open control panel >>system and security >> file system

7 0
2 years ago
Read the attached paper titled A Survey of Coarse-Grained Reconfigurable Architecture and comment on it. Make sure to specifical
Pani-rosa [81]

Answer:

lol

Explanation:

I NEED POINTS

5 0
1 year ago
Temperature Class Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperatur
posledela

Answer:

Explanation:

   public class Temperature

   {

       double ftemp;

       public int Constructor(double fahrenheit)

       {

           ftemp = fahrenheit;

          return Convert.ToInt32(ftemp);

       }

       public void setFahrenheit(double fahrenheit)

       {

           ftemp = fahrenheit;

       }

       public void getFahrenheit()

       {

           ftemp = Constructor(ftemp);

       }

       public void getCelcius()

       {

           ftemp = (ftemp - 32) * 5 / 9;

       }

       public void getKelvin()

       {

           ftemp = (ftemp - 32) * 5 / 9 + 273.15;

       }

   }

8 0
2 years ago
Anna bought a box of blueberries for £7. She used 700 grams for a cheesecake and she has 450 grams left. How much did the bluebe
xxTIMURxx [149]

0.61 (rounded up)

Explanation:

You add both 700 and 450 which will give you 1150g

You then divide 1150 by 100 which gives you 11.5

Then divide 7 by 11.5 which will give you 0.61 as cost of every 100 grams

8 0
2 years ago
When researching which keywords should be included in a résumé, what four sources are valuable resources?
zimovet [89]
I would suggest the following sources

1) job postings - those offer include the phrases that the employers themselves want to hear

2) keyword lists - they're made for looking for keywords!

3) professional site's skills sections. You could use LinkedIn or any other professional site.

4)Sometimes you can find software that can suggest keywords for you
4 0
2 years ago
Read 2 more answers
Other questions:
  • What is the argument in this function =AVERAGE(F3:F26)
    15·1 answer
  • Prove that f(n) = 20n3 + 10nlogn + 5 is O(n3)
    12·1 answer
  • Which mechanisms do we use to transport binary data and memory addresses?
    7·1 answer
  • Information in​ folders, messages,​ memos, proposals,​ emails, graphics, electronic slide​ presentations, and even videos create
    7·1 answer
  • 1. (1 point) Which flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination? 2.
    13·1 answer
  • Which of the following is true about sorting functions?
    14·1 answer
  • On the planet Sigma, robots excavate chunks of a very precious cristaline. These chunks can be divided into smaller part only on
    15·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • When you check to see how much RAM, or temporary storage you have available, you are checking your _____.
    7·1 answer
  • B2B partners often connect to each other on the Internet through special __________ designed to facilitate information exchanges
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!