当前位置:网站首页>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

边栏推荐
- 2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
- The basis of C language grammar -- function nesting, Fibonacci sum of recursive applet and factorial
- Force buckle ----- remove the maximum and minimum values from the array
- Redis novice introduction
- Develop current learning objectives and methods
- Crawler related articles collection: pyppeter, burpsuite
- 如何更改微信小程序二维码物料颜色
- Testing practice - App testing considerations
- libmagic 介绍
- 软件测试---如何选择合适的正交表
猜你喜欢
随机推荐
1. 两数之和(LeetCode题目)
String类intern()方法和字符串常量池
SSM项目小例子,SSM整合图文详细教程
When will JVM garbage collection enter the older generation
【二分查找】4. 寻找两个正序数组的中位数
测试实践——app 测试注意点
LSP 是什么
This new change of go 1.16 needs to be adapted: the changes of go get and go install
#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
Openxcap usage
2. merge two ordered arrays
echo $?
c语言语法基础之——函数定义学习
Differences between JVM, Dalvik and art
In the fragment, the input method is hidden after clicking the confirm cancel button in the alertdialog (this is valid after looking for it on the Internet for a long time)
Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
创建对象的时候堆内存的分配
druid数据源实现后台监控
【深度优先搜索】312.戳气球
How do technicians send notifications?








