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]
1 year 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]1 year 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
Dr. Apple wants to study a drug to manage diabetes in adolescents. The researcher plans to use an electronic informed consent (e
GarryVolchara [31]

Answer: Yes, the eIC could be used for assent.

Explanation:

Electronic informed consent (eIC) may be used for seeking, confirming and documenting informed consent.

5 0
1 year ago
Read 2 more answers
What three things in the third generation of computing helped get programming enthusiasts more involved with computers? Select 3
andrew11 [14]

Answer:

ipods, windows 10,intengrated circut

Explanation:

5 0
2 years ago
Read 2 more answers
Which is true for a hosted blog software
professor190 [17]
Since you have not provided the choices wherein I will have to choose from to arrive at an answer, I will just explain to you the concept revolving around a hosted blog software. Hosted blog software are basically installed by the owner of the web server in which among its famous platforms is the Blogger.
7 0
1 year ago
Read 2 more answers
Which of the following describes ETL? a) A process that transforms information using a common set of enterprise definitions b) A
andrezito [222]

Answer:

The correct answer is d) All of these are correct.

Explanation:

ETL stands for Extract, Transform and Load. An ETL system extracts data from the sources, enforces data quality and consistency standards, conforms data so that separated and maybe unrelated sources can be used together, and as a final step delivers data in presentation-ready formats so that developers can build applications and end users can take decisions.

4 0
1 year ago
The Security Development Life Cycle (SDLC) is a general methodology for the design and implementation of an information system.
navik [9.2K]

Answer:

False

Explanation:

The Security Development Life Cycle (SDLC), is a software development which involves traditional approach towards its design such as, waterfall model, Agile, etc.

It can either be referred to as a generic secure development life cycle or a specific one, such as the Microsoft SDL or the Cisco SDL.

Its phases includes,

A1 - Security Assessment

A2 - Architecture

A3 - Design and Development 1

A4 - Design and Development 2

A5 - Ship

PRSA - Post Release

Each phase talks about how a secured software is developed.

The Security Development Life Cycle (SDLC) is a general methodology for the design and implementation of an information system. This statement is false because by definition and attributes Security Development Life Cycle is a traditional approach towards software development and not a general method.

6 0
1 year ago
Other questions:
  • A slide contains three text boxes and three images that correspond to the text boxes. Which option can you use to display a text
    5·2 answers
  • Convert the following binary number to octal (111000)2​
    12·1 answer
  • Design a BCD-to-Gray code decoder. Your decoder will have 4 inputs: A, B, C and D, representing a 4-bit BCD code (A being the MS
    7·2 answers
  • Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *thi
    15·1 answer
  • How can a signature be added to an email message? Check all that apply.
    10·2 answers
  • SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick R
    9·1 answer
  • Are bpos safe for organisations ? State your views on it
    8·1 answer
  • Television broadcasts were originally delivered by using which technology
    14·1 answer
  • Accenture has partnered with a global construction company that specializes in building skyscrapers. The company wants better ma
    12·1 answer
  • You are a security consultant and have been hired to evaluate an organization's physical security practices. All employees must
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!