我可以操作我的数组来打印一个索引起始点吗?
我的数组索引从 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/