import java.util.*;
public class Demo29 {
public static void main(String[] args) {
int [] oldArr ={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
int[] newArr=clearZero(oldArr);
System.out.println("新数组的元素:"+ Arrays.toString(newArr));
}
public static int[] clearZero(int [] oldArr) {
int count=0;
for(int i=0;i<oldArr.length;i++) {
if(oldArr[i]==0) {
count++;
}
}
int [] newArr=new int [oldArr.length-count];
int index=0;
for(int i=0;i<oldArr.length;i++) {
if(oldArr[i]!=0) {
newArr[index++]=oldArr[i];
}
}
return newArr;
}
}