当前位置:网站首页>Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
2022-06-26 10:21:00 【m0_ sixty-one million nine hundred and sixty-one thousand eight】
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);
}
}
The result is 15
边栏推荐
- Pytest configuration file
- MySQL第四章总结
- Global and Chinese markets of children's electronic thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
- Call API interface to generate QR code of wechat applet with different colors
- 动态库连接 - 符号冲突 - 全局符号介入
- DBSCAN
- Poj3682 king arthur's birthday celebration (probability)
- MySQL第五章总结
- MySQL第六章总结
- MySQL项目7总结
猜你喜欢
Detailed explanation of winsorflow quantum installation process
thymeleaf中抽取公共片段
Druid data source for background monitoring
Call API interface to generate QR code of wechat applet with different colors
Develop current learning objectives and methods
MySQL learning summary
The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
Use of exec series functions (EXECL, execlp, execle, execv, execvp)
About multi table query of MySQL
Allocation of heap memory when creating objects
随机推荐
Blog article index summary -- Software Engineering
TensorFlow动态分配显存
創建對象的時候堆內存的分配
Establishment of smart dialogue platform for wechat official account
首批12家企业入驻!广州首个集中展销老字号产品专柜开张
[binary search] 4 Find the median of two positive arrays
Solution to network request crash in retrofit2.8.1
【二分查找】4. 寻找两个正序数组的中位数
The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
904. 水果成篮
Under the double reduction, the amount of online education has plummeted. Share 12 interesting uses of webrtc
Detailed explanation of winsorflow quantum installation process
A list of common methods for customizing paint and canvas of view
Cloud native essay using Hana expression database service on Google kubernetes cluster
904. fruit baskets
LSP 是什么
[sans titre]
Druid data source for background monitoring
1. sum of two numbers (leetcode topic)
Solution to the problem of compilation error due to repeated third-party package names