-2

Array Problem 3: 2D array -Ask the user for 4 integers -Store them as a 2x2 matrix -Find the determinant Matrix: input1 input2 input3 input4

1 Answers1

1

Something like this will do it. Next time please show us what you have tried, so we can help more effectively.

public class Main {

public static void main(String[] args) {
        int[][] matrix = new int[2][2];
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter 4 integers:");
        matrix[0][0] = scanner.nextInt();
        matrix[0][1] = scanner.nextInt();
        matrix[1][0] = scanner.nextInt();
        matrix[1][1] = scanner.nextInt();
        //I hope I remember 2x2 determinant correctly...
        int det = matrix[0][0]*matrix[1][1] - matrix[1][0]*matrix[0][1];
        System.out.println("Determinant is: " + det);
    }

}
Gtomika
  • 845
  • 7
  • 24