-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemZero.java
More file actions
33 lines (30 loc) · 787 Bytes
/
RemZero.java
File metadata and controls
33 lines (30 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.ArrayList;
import java.util.Scanner;
public class RemZero {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []nums = new int[n];
for(int i = 0; i < nums.length; i++){
nums[i] = sc.nextInt();
}
int c= 0;
ArrayList<Integer> ls = new ArrayList<>();
for(int num : nums){
if(num == 0){
c += 1;
}else{
ls.add(num);
}
}
while(c-- > 0){
ls.add(0);
}
for(int i = 0; i < nums.length; i++){
nums[i] = ls.get(i);
}
for(int num : nums){
System.out.print(num + " ");
}
}
}