题目
输入描述
输入有多个测试用例,每个测试用例第一行为一个整数n(n<=1000),表示方阵阶数为n。接下来是n行的数字,每行n个数用空格隔开。
输出描述
输出一个整数,表示n阶方阵的和。
示例1
输入
3
1 2 3
2 1 3
3 2 1
输出
18
思路
直接上代码~
代码
import java.util.Scanner;
public class NSquareMatrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans = 0, x;
for(int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
x = sc.nextInt();
ans += x;
}
}
System.out.println(ans);
}
}