java - 我可以操作数组来打印索引起始点吗?

标签 java arrays

我可以操作我的数组来打印一个索引起始点吗?

我的数组索引从 0 开始,这很好,但我希望它在我的输出中看起来像从 1 开始。有没有办法做到这一点?这是我的 for 循环:

for( x=0;x<3;x++) {
  for( i=0;i<4;i++) {
    if(rounded[i][x]<395 || rounded[i][x] >405) {
        System.out.println("there is an error with point "+i+"on element"+x+"as the temperature is at"+rounded[i][x]);
    }
  }
} 

最佳答案

为什么不在输出处简单地加 1?

 for( x=0;x<3;x++)
 {
    for( i=0;i<4;i++)
    {
        if(rounded[i][x]<395 || rounded[i][x] >405)
        {
            System.out.println("there is an error with point "+(i+1)+"on element"+x+"as the temperature is at"+rounded[i][x]);
        }
    }
  }

关于java - 我可以操作数组来打印索引起始点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099879/

相关文章:

java - 数组函数的时间复杂度

ios - 与数组匹配的 Swift 开关模式

java - Wicket 快速双击提交按钮

c# - 将 GUI 导出为 XML?

java - 如何控制 Java Futures 为 "submitted"的订单?

java - 如何在 Android 中经过一定时间后停止 BufferedReader

c# - 使用 Linq to SQL 简化创建数组列

JavaScript:数组与对象数组

javascript - JS函数计算数组中的奇数和负数

java - GUI 构建后启动线程