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
Asked
Active
Viewed 190 times
-2
-
Did you try anything? You should show a [mcve]. – EJoshuaS - Stand with Ukraine Oct 15 '19 at 16:14
-
1Could you please add the program which you have tried so far? so we can help you to correct the mistakes. What is the purpose of this question? is this case required on any of your existing systems or are you practicing it to gain knowledge in Java – Ganesa Vijayakumar Oct 15 '19 at 16:23
1 Answers
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