我可以操作我的数组来打印出一个索引起点吗?
我的数组索引从 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]);
}
}
}
您可以向两个循环计数器添加一个以进行显示,例如 -
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 "
+ (1+i) + " on element " + (1+x)
+ " as the temperature is at " + rounded[i][x]);
}
}
}