How I can index the array starting from 1 instead of zero?

后端 未结 5 1006
滥情空心
滥情空心 2020-12-10 09:46
for (int i = 0; i < reports.length; i++) {

  Products[] products = reports[i].getDecisions;

  for (int j = 0; j < products.length; j++) {

  }
}
5条回答
  •  感情败类
    2020-12-10 10:22

    You can't do that as array index in Java starts from 0. But you can access array with index 1 with little modifications.

    Example: Consider an integer array "a" with length n

    for(int i=0;i

    This can be modified as:

    int a[] = new int[n+1];
    for(int i=1;i

提交回复
热议问题