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

边栏推荐
- LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value
- P1296 whispers of cows (quick row + binary search)
- Allocation de mémoire tas lors de la création d'objets
- What you need to know to test -- URL, weak network, interface, automation
- exec系列函数(execl、execlp、execle、execv、execvp)使用
- The basis of C language grammar -- learning of local variables and storage categories, global variables and storage categories, and macro definitions
- 什么是僵尸网络
- echo $?
- c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
- Nested recyclerview in nestedscrollview automatically slides to the bottom after switching
猜你喜欢

WIN10系统实现Redis主从复制

【Leetcode】76. Minimum covering substring

DAY 3 数组,前置后置,字符空间,关键词和地址指针

118. Yanghui triangle

Appium自动化测试基础 — 移动端测试环境搭建(二)

【Leetcode】76. 最小覆盖子串

Use of exec series functions (EXECL, execlp, execle, execv, execvp)

118. 杨辉三角

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

logback
随机推荐
Detailed explanation of winsorflow quantum installation process
libgstreamer-1.0. so. 0: cannot open shared object file: No such file or directory
JVM垃圾回收什么情况会进入老年代
thymeleaf中抽取公共片段
存储过程测试入门案例
jar版本冲突问题解决
SQL advanced tutorial
[sans titre]
全渠道、多场景、跨平台,App如何借助数据分析渠道流量
創建對象的時候堆內存的分配
自动化测试——pytest本身及第三方模块介绍及使用
Redis notes (13) - scan and keys search for specific prefix key fields (command format, usage examples, locating large keys)
【深度优先搜索】312.戳气球
Full introduction to flexboxlayout (Google official flexible implementation of flow layout control)
Luogu 1146 coin flip
Allocation of heap memory when creating objects
What is LSP
Go learning notes (83) - code specification and common development skills
What is the web SSH service port of wgcloud
The first batch of 12 enterprises settled in! Opening of the first time-honored product counter in Guangzhou