int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};
public static void main(String[] args) {
// 定义方法,将数组int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};去掉0变成一个新数组,并升序排列
int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};
System.out.println(Arrays.toString(parse(arr)));
}
private static int[] parse(int[] arr) {
int len=0;
for (int num : arr) {
if(num!=0)
len++;
}
int[] arr1=new int[len];
for (int n : arr) {
if(n!=0)
arr1[–len]=n;
}
Arrays.sort(arr1);
return arr1;
}
相关文章
- 12-042021-09-25
- 12-042021-09-25
- 12-042021-09-25
- 12-042021-09-25
- 12-042021-09-25
- 12-042021-09-25 XAMPP