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

边栏推荐
- MySQL第四章总结
- 1. 两数之和(LeetCode题目)
- Index summary of blog articles -- Industrial Internet
- 【LeetCode】59. 螺旋矩阵 II
- Problems encountered by jupyter notebook
- Druid data source for background monitoring
- How to find and install the dependent libraries of Debian system
- Call API interface to generate QR code of wechat applet with different colors
- 118. Yanghui triangle
- From TF 1 X to TF 2.6 (update if you encounter it)
猜你喜欢

Little red book - Summary of internal sales spike project

Basic grammar of C language -- pointer (character, one-dimensional array) learning

Small example of SSM project, detailed tutorial of SSM integration

Establishment of smart dialogue platform for wechat official account

How to change the QR code material color of wechat applet

What should the preview do?

904. fruit baskets

The IE mode tab of Microsoft edge browser is stuck, which has been fixed by rolling back the update

cmake / set 命令

SSM项目小例子,SSM整合图文详细教程
随机推荐
Appium automation test foundation - mobile end test environment construction (II)
Blog article index Summary - wechat games
libmagic 介绍
Day 3 array, pre post, character space, keyword and address pointer
Solution to network request crash in retrofit2.8.1
Cento7.7 elk installation simple record
echo $?
JVM的符号引用和直接引用是什么
1. sum of two numbers (leetcode topic)
Tensorflow dynamically allocates video memory
How to start the learning journey of webrtc native cross platform development?
调用api接口生成不同颜色的微信小程序二维码
Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
The basis of C language grammar -- function definition learning
Automated testing -- on the coexistence of Unitest and pytest initialization
Full introduction to flexboxlayout (Google official flexible implementation of flow layout control)
Software testing - how to select the appropriate orthogonal table
MySQL项目7总结
Little red book - Summary of internal sales spike project
Dynamic library connection - symbol conflict - global symbol intervention