我需要显示数组的索引,但不是从 0 开始并经过 4。我需要它显示 1,然后经过 5。我认为这会很容易找到,但我已经搜索了几个小时并且找不到我的问题的解决方案。我将在下面发布我的代码。
最佳答案
只需在循环中的参数中添加 1:
int[] myArray = new int[5];
for(int x = 0; x < myArray.length; x++){
System.out.println("Array value at index " + (x + 1) + " is " + myArray[x]);
}
关于java - 如何在java中显示索引位置但+1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48914372/