解题思路:
注意事项:
参考代码:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m[]=new int[n];
int z=0;
for (int i=0;i<m.length;i++){
m[i]=sc.nextInt();
}
for (int ij=0;ij<m.length;ij++) {
for (int j = 0; j < m.length - 1; j++) {
if (m[j] == 0) { //交换
m[j] = m[j + 1];
m[j+1]=0;
}
}
}
for (int k=0;k<n;k++){
if(m[k]==0){
z++;
}
}
m = Arrays.copyOf(m, m.length-z); //缩短数组
for (int x=0;x<m.length;x++){
System.out.printf(m[x]+" ");
}
System.out.printf("\n");
System.out.printf(""+m.length);
}
}
0.0分
1 人评分
点我有惊喜!你懂得!浏览:1221 |
C语言训练-斐波纳契数列 (C语言代码)浏览:776 |
C语言训练-最大数问题 (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:689 |
用筛法求之N内的素数。 (C语言代码)浏览:1239 |
C语言训练-求PI* (C语言代码)浏览:614 |
printf基础练习2 (C语言代码)浏览:644 |
C语言训练-亲密数 (C语言代码)浏览:682 |
整数平均值 (C语言代码)浏览:783 |
矩阵的对角线之和 (C语言代码)浏览:1350 |