-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroToEnd.java
More file actions
29 lines (26 loc) · 771 Bytes
/
ZeroToEnd.java
File metadata and controls
29 lines (26 loc) · 771 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
import java.util.Scanner;
public class ZeroToEnd {
public static void zeroToEnd(Integer[] arr) {
int count = 0;
for (int i = 0; i < arr.length; i++) {
if(arr[i] != 0 ) {
arr[count++] = arr[i];
}
}
while (count < arr.length)
arr[count++] = 0;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Integer n = scan.nextInt();
Integer arr[] = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
zeroToEnd(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i].toString() + " ");
}
scan.close();
}
}