解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int [] arr=new int [a]; int index=0; //找到有多少个0 for(int i=0;i<a;i++) { arr[i]=sc.nextInt(); if(arr[i]==0) { index++; } } //去掉0后的数组长度 int [] s1=new int [a-index]; int k=0; for(int i=0;i<a;i++) { if(arr[i]!=0) { s1[k++]=arr[i]; } } //遍历出来 for(int i=0;i<s1.length;i++) { System.out.print(s1[i]+" "); } System.out.println(); System.out.println(s1.length); } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:324 |
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1040 |
汽水瓶 (C语言代码)浏览:698 |
Tom数 (C++代码)浏览:827 |
C语言程序设计教程(第三版)课后习题9.8 (Java代码)浏览:1638 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:660 |
三角形 (C语言代码)浏览:908 |
C语言考试练习题_保留字母 (C语言代码)浏览:700 |
核桃的数量 (C语言代码)浏览:669 |
A+B for Input-Output Practice (III) (C语言代码)浏览:566 |