-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenOddArray.java
More file actions
37 lines (31 loc) · 980 Bytes
/
Copy pathEvenOddArray.java
File metadata and controls
37 lines (31 loc) · 980 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
import java.util.Arrays;
import java.util.Scanner;
public class EvenOddArray{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length of array : ");
int[] array = new int[sc.nextInt()];
System.out.println("Enter the elements of the array : ");
for(int i = 0; i<array.length;i++){
array[i] = sc.nextInt();
}
int [] temp = new int[array.length];
int j =0;
int k = array.length-1;
for(int i = 0; i<array.length;i++){
if(array[i]%2!=0){
temp[j++] = array[i];
}
else{
temp[k--] = array[i];
}
}
copyArray(temp , array);
System.out.println(Arrays.toString(array));
}
public static void copyArray(int arr[] , int [] num){
for(int i =0; i<arr.length;i++){
num[i] = arr[i];
}
}
}