作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的其他对角线方法无法正常工作。
public int sumOtherDiag()
{
int otherDiag = 0;
for (int i = 0; i < square.length−1; i++)
{
otherDiag += square[i][i];
}
return otherDiag;
}
我没有可以在此处显示的输出,但是有人立即发现有什么问题吗?
此方法应该将元素相加并获得幻方第二条对角线(从右下开始)的总和。例如,如果我的方 block 是
01 04 03
03 05 04
05 02 04
它将输出
03 + 05 + 05 = 并得到 13
但是我的实际输出打印的数字也比预期的要少。
(没有我的输出很难解释。稍后当我访问我的程序时我会上传它)
任何帮助将不胜感激,谢谢!
最佳答案
public int sumOtherDiag()
{
int otherDiag = 0;
int count = square.length;
for (int i = 0; i < square.length; i++)
{
otherDiag += square[i][--count];
}
return otherDiag;
}
关于java - 幻方 其他对角线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28335311/
我正在一个 nodejs 服务器上工作,它将发布的 html 呈现为 pdf、png 或 jpg。( https://github.com/svenhornberg/pagetox (server.j
我是一名优秀的程序员,十分优秀!