解题思路:
注意事项:
参考代码:
import java.util.Arrays; import java.util.Scanner; import javax.swing.text.html.CSS; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[][] n = new int[3][3]; int a = 0, b = 0, c = 0; for (int i = 0; i < n.length; i++) { for (int j = 0; j < n[i].length; j++) { n[i][j] = scanner.nextInt(); } } // 每行之和都相等 for (int j = 0; j < 3; j++) { a = a + n[j][0]; b = b + n[j][1]; c = c + n[j][2]; } if (a == b && b == c) { // 每列之和都相等 for (int j = 0; j < 3; j++) { a = a + n[0][j]; b = b + n[1][j]; c = c + n[2][j]; } if (a == b && b == c) { // 对角线之和都相等 a = a + n[0][0]+ n[1][1]+ n[2][2]; b = b +n[2][2]+ n[1][1]+ n[0][0]; if (a == b) { System.out.print(1); } else { System.out.print(0); } } else { System.out.print(0); } } else { System.out.print(0); } } }
0.0分
0 人评分
简单的a+b (C语言代码)浏览:528 |
C语言程序设计教程(第三版)课后习题9.4 (Java代码)浏览:1446 |
简单的a+b (C语言代码)浏览:641 |
WU-字符串比较 (C++代码)浏览:824 |
IP判断 (C语言代码)浏览:820 |
矩形面积交 (C++代码)浏览:1204 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:569 |
Quadratic Equation (C语言代码)浏览:1034 |
企业奖金发放 (C语言代码)浏览:2462 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:587 |