[英]JAVA How do I write code for a 2D array storing four integers in a 2x2 matrix?
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数组问题 3:二维数组 - 向用户询问 4 个整数 - 将它们存储为 2x2 矩阵 - 找到行列式矩阵:input1 input2 input3 input4
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.