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

边栏推荐
- 【二分查找】4. 寻找两个正序数组的中位数
- [binary search] 4 Find the median of two positive arrays
- 【LeetCode】59. Spiral matrix II
- Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
- String constant pool, class constant pool, and runtime constant pool
- How to change the QR code material color of wechat applet
- 微软 Edge 浏览器 IE 模式标签页出现卡死情况,已通过回滚更新修复
- Full introduction to flexboxlayout (Google official flexible implementation of flow layout control)
- libmagic 介绍
- mysql学习总结
猜你喜欢

The basis of C language grammar -- pointer (multidimensional array, function, summary) learning

Hcia-dhcp experiment

Basic string operations in C

MySQL learning summary

A list of common methods for customizing paint and canvas of view

Solution to network request crash in retrofit2.8.1

Renesas electronics launched a complete intelligent sensor solution for Internet of things applications

【Leetcode】76. Minimum covering substring

【LeetCode】59. Spiral matrix II

Redis master-slave replication in win10 system
随机推荐
MySQL第四章总结
[depth first search] 312 Poke balloon
cmake / set 命令
Recyclerview implements flow layout (LinearLayout with line wrap) (flexboxlayoutmanager)
MySQL learning summary
[binary search] 4 Find the median of two positive arrays
Automated testing -- Introduction and example of pytest framework
36 qtextedit control input multiline text
Learning and understanding of thread pool (with code examples)
Win10安装tensorflow-quantum过程详解
Configuration internationale
What is the web SSH service port of wgcloud
Detailed explanation of winsorflow quantum installation process
Servlet learning notes II
Small example of SSM project, detailed tutorial of SSM integration
Introduction to libmagic
Svn command
美国总统签署社区安全法案以应对枪支问题
Luogu 1146 coin flip
druid数据源实现后台监控