KnowledgeBoat Logo
|

Computer Applications

Define a class to accept values into a 3x3 integer array and print the product of each row elements.

Example:

312
421
512

Output:

Row 0 – 6
Row 1 – 8
Row 2 – 10

Java

Java Arrays

5 Likes

Answer

import java.util.Scanner;

public class RowProduct {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] arr = new int[3][3];

        System.out.println("Enter 9 integers for the 3x3 array:");
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                arr[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < 3; i++) {
            int product = 1;
            for (int j = 0; j < 3; j++) {
                product *= arr[i][j];
            }
            System.out.println("Row " + i + " – " + product);
        }
    }
}

Output

BlueJ output of Define a class to accept values into a 3x3 integer array and print the product of each row elements. Example: Output: Row 0 – 6 Row 1 – 8 Row 2 – 10

Answered By

1 Like


Related Questions