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
lianna [129]
1 year ago
14

Q4 a.

Engineering
1 answer:
dedylja [7]1 year ago
7 0

The Java program that accepts a matrix of M × N order and then interchanges diagonals of the matrix is given below:

<h3>Steps:  </h3>
  • 1. We can only interchange diagonals for a square matrix.
  • 2. Therefore, we would have to create a square matrix of size [M × M].
  • 3. We would check whether the matrix is a square matrix or not. If the matrix is square then follow step 3 else terminate the program.
  • 4. Apply logic for interchange diagonal of the matrix some logic is given below.

<h3>Java Code</h3>

//  Java Program to Accept a Matrix of Order M x N &

//  Interchange the Diagonals

import java.util.Scanner;

public class InterchangeDiagonals {

   public static void main(String[] args)

   {

       // declare variable

       int m, n, i, j, temp;

       // create a object of scanner class

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter number of rows ");

       // take number of rows

       m = sc.nextInt();

       System.out.print("Enter number of columns ");

       // take number of columns

       n = sc.nextInt();

       // declare a mxn order array

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

       // if block it's execute when m is equals to n

       if (m == n) {

           System.out.println(

               "Enter all the values of matrix ");

           // take the matrix inputs

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

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

                   a[i][j] = sc.nextInt();

               }

           }

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

           // print the original matrix

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

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

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

               }

               System.out.println("");

           }

          // perform interchange

           for (j = 0; j < m; j++) {

               temp = a[j][j];

               a[j][j] = a[j][n - 1 - j];

               a[j][n - 1 - j] = temp;

           }

           System.out.println(

               " after interchanging diagonals of matrix ");

           // print interchanged matrix

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

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

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

               }

               System.out.println("");

           }

       }

       // else block it's only execute when m is not equals

       // to n

       else {

           System.out.println("Rows not equal to columns");

       }

   }

}

Read more about java programming here:

brainly.com/question/18554491

#SPJ1

You might be interested in
(a) A 10.0-mm-diameter Brinell hardness indenter produced an indentation 2.3 mm in diameter in a steel alloy when a load of 1000
vampirchik [111]

Answer:

(a)  We are asked to compute the Brinell hardness for the given indentation. for HB, where P= 1000 kg, d= 2.3 mm, and D= 10 mm.  

Thus, the Brinell hardness is computed as

HB=2P/\pi D{D-\sqrt{D^2-d^2}

=2*1000hg/\pi (10mm)[10mm-\sqrt{(1000^2-(2.3mm)^2} ]

(b)    This  part  of  the  problem  calls  for  us  to  determine  the  indentation diameter d which  will  yield  a  270  HB  when P=  500  kg.  

d=\sqrt{D^2-[D-\frac{2P}{(HB)\pi D} } ]^2\\=\sqrt{(10mm)^2-[10mm-\frac{2*500}{450( \pi10mm)} } ]^2

6 0
4 years ago
Ayuda!<br> es para mañana
ExtremeBDS [4]
No se ve la foto :( puedes a ser la pregunta otra ves?
8 0
3 years ago
Khái niệm về môi trường nhiệt nóng và môi trường nhiện lạnh ?
I am Lyosha [343]

Explanation:

उह्ह्नमजज्ल्ह्ह्बनुतनकुहक्जो

7 0
3 years ago
SE DEBE CONTRUIR UNA PARED QUE TENDRÁ 4 METROS DE LARGO POR 3 METROS
Marizza181 [45]

Answer:

you pagil

Explanation:

8 0
3 years ago
Identify three questions a patient might ask of the nuclear medicine technologist performing a nuclear medicine exam.
bogdanovich [222]

Answer:

How long is my nuclear medicine exam?

How long will the radioactivity stay in my system?

What are the risks?

Explanation:

3 0
2 years ago
Other questions:
  • A closed system contains propane at 35°c. It produces 35 kW of work while absorbing 35 kW of heat. What is process? the temperat
    7·1 answer
  • Info security:
    8·1 answer
  • A large class with 1,000 students took a quiz consisting of ten questions. To get an A, students needed to get 9 or 10 questions
    10·1 answer
  • In sleep, what does REM stand for?
    10·1 answer
  • Identify each letter in the lift equation and list acceptable units for each quantity
    5·2 answers
  • Please help me please
    10·1 answer
  • Why is Ethics an important part of engineering?
    8·1 answer
  • A transformer has a 120/208-volt wye secondary. If the current in each of the secondary coils (or windings) is 75 amps, what is
    6·1 answer
  • What is the Crankshaft Turk ,Connecting rod Turk and Flywheel Turk for the 5a engine
    6·1 answer
  • A kitchen contains one section of counter that's 20 inches
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!