Computer Science, asked by rupalmaitra8, 1 day ago

WAP in JAVA to creat a 4X4 matrix and store the different no.s using input statement ,find the product of the elements storedm in each rows and each columns and display the result

Answers

Answered by boysagod1567
1

import java.util.Scanner;

public class KboatDDARowSwap

{

   public static void main(String args[]) {

       Scanner in = new Scanner(System.in);

       int arr[][] = new int[4][4];

       

       System.out.println("Enter elements of 4x4 array ");

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

           System.out.println("Enter Row "+ (i+1) + " :");

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

               arr[i][j] = in.nextInt();

           }

       }

       

       System.out.println("Input Array:");

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

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

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

           }

           System.out.println();

       }

       

       //Swap 0th and 3rd rows

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

           int t = arr[0][j];

           arr[0][j] = arr[3][j];

           arr[3][j] = t;

       }

       

       System.out.println("Swapped Array:");

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

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

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

           }

           System.out.println();

       }

   }

}

OUTPUT

BlueJ output of Write a program in Java to create a 4 x 4 matrix. Now, swap the elements of 0 th row with 3 rd row correspondingly. Display the result after swapping. Sample Input Sample Output

Similar questions