0% found this document useful (0 votes)
2 views

22BSA10278 harsh chouhan Matrix Assignment Java

The document provides a Java program for multiplying the elements of a 3x3 matrix by columns. It includes user input for the matrix elements, displays the original matrix, and outputs the multiplication results for each column. The program utilizes methods for printing the matrix and calculating column multiplications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

22BSA10278 harsh chouhan Matrix Assignment Java

The document provides a Java program for multiplying the elements of a 3x3 matrix by columns. It includes user input for the matrix elements, displays the original matrix, and outputs the multiplication results for each column. The program utilizes methods for printing the matrix and calculating column multiplications.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Matrix Assignment(Java)

Solution:-

import java.util.Scanner;

public class TwoDArrayMultiplication {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int[][] matrix = new int[3][3];

System.out.println("Enter the elements of a 3x3 matrix:");


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

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

System.out.print("Enter element at position (" + (i + 1) + ", " + (j + 1) + "): ");

matrix[i][j] = scanner.nextInt();

System.out.println("The original matrix is:");

printMatrix(matrix);

System.out.println("Multiplication of elements in each column:");

int[] columnMultiplications = getColumnMultiplications(matrix);

for (int col = 0; col < 3; col++) {

System.out.println("Column " + (col + 1) + " multiplication result: " + columnMultiplications[col]);

scanner.close();

private static void printMatrix(int[][] matrix) {

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

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

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

System.out.println();

private static int[] getColumnMultiplications(int[][] matrix) {

int[] columnMultiplications = new int[3];


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

int columnProduct = 1;

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

columnProduct *= matrix[i][j];

columnMultiplications[j] = columnProduct;

return columnMultiplications;

Output:-

You might also like