我编写了以下代码来查找数组中的最后一个零索引:
public class Stack {
public static void main(String[] args){
int[] a=new int[5];
a[0]=1;
a[1]=0;
a[2]=90;
a[3]=0;
a[4]=4;
findLast(a);
}
public static int findLast(int[] x){
for(int i=0;i<x.length;i++){
if(x[i]==0){
System.out.println(i);
}
}
return 0;
}
}
输出如下:
1
3
我真正想要的是索引 3。