当前位置:网站首页>3行3列整形二维数组,求对角之和
3行3列整形二维数组,求对角之和
2022-06-26 09:37:00 【m0_61961898】
public static void main(String[] args) {
int sum = 0;
int z [][]=new int [3][3];
z[0] = new int [] {1, 2, 3};
z[1] = new int [] {4, 5, 6};
z[2] = new int [] {7, 8 ,9};
for (int i=0 ;i<3;i++) {
for (int j=0; j<3;j++) {
if (i ==j) {
sum = sum + z[i][j];
}
}
}
System.out.println( sum);
}
}结果为15

边栏推荐
- Vscode common programming fonts
- 1. sum of two numbers (leetcode topic)
- US President signs community safety act to deal with gun issue
- Software testing - how to select the appropriate orthogonal table
- Leetcode intermediate node of linked list
- cmake / set 命令
- Extracting public fragments from thymeleaf
- 2. 合并两个有序数组
- 创建对象的时候堆内存的分配
- Control setting layout in linear layout_ Gravity doesn't work?
猜你喜欢

WGCLOUD的web ssh服务端口是多少

Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)

Differences between JVM, Dalvik and art

exec系列函数(execl、execlp、execle、execv、execvp)使用

P1296 whispers of cows (quick row + binary search)

【Leetcode】76. Minimum covering substring

國際化配置

Software testing - how to select the appropriate orthogonal table

【LeetCode】59. 螺旋矩阵 II

What is the web SSH service port of wgcloud
随机推荐
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
Daily-used English phrases
Automated testing -- Introduction and use of pytest itself and third-party modules
The basis of C language grammar -- function definition learning
Automated testing -- Introduction and example of pytest framework
WIN10系统实现Redis主从复制
Constraintlayout control uses full Raiders
调用api接口生成不同颜色的微信小程序二维码
Teach you to use shell script to check whether the server program is running
Automated testing -- on the coexistence of Unitest and pytest initialization
Differences between JVM, Dalvik and art
SSM项目小例子,SSM整合图文详细教程
The IE mode tab of Microsoft edge browser is stuck, which has been fixed by rolling back the update
When will JVM garbage collection enter the older generation
String类intern()方法和字符串常量池
【Leetcode】76. Minimum covering substring
Tensorflow dynamically allocates video memory
自动化测试——关于unitest与pytest初始化共存问题
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
Logical English structure [key points]