-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion5.java
More file actions
33 lines (27 loc) · 800 Bytes
/
question5.java
File metadata and controls
33 lines (27 loc) · 800 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
public class question5 {
public static void main(String[] args) {
int arr[]={-1,-20,30,40,50,-8};
int n =arr.length;
question5(arr, n);
for(int i : arr){
System.out.println(i +" ");
}
}
private static void question5 (int[]arr,int n){
int tempAll[] = new int[n];
int j = 0;
for(int i = 0; i < n; i++){
if(arr[i]<0){
tempAll[j++] = arr[i];
}
}
for (int i = 0; i < n; i++){
if(arr[i] >= 0) {
tempAll[j++] = arr[i];
}
}
for (int i = 0; i < n; i++){
arr[i] = tempAll[i];
}
}
}