-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers.java
More file actions
37 lines (35 loc) · 842 Bytes
/
numbers.java
File metadata and controls
37 lines (35 loc) · 842 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
33
34
35
36
37
public class numbers {
public static void main(String args[]) {
int arr[] = { 1, -2, 7, -3, -1, 16, 23 };
int negCount = 0, posCount = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < 0) {
negCount++;
} else {
posCount++;
}
}
System.out.println(posCount);
int negArr[] = new int[negCount];
int posArr[] = new int[posCount];
int k = 0;
int l = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < 0) {
negArr[k] = arr[i];
k++;
} else {
posArr[l] = arr[i];
l++;
}
}
for(int i=0;i<negArr.length;i++){
System.out.print(negArr[i]+" ");
}
System.out.println();
for(int i=0;i<posArr.length;i++){
System.out.print(posArr[i]+" ");
}
// concatenate these two arrays
}
}