-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathRemove_Even_Integers.java
41 lines (32 loc) · 964 Bytes
/
Remove_Even_Integers.java
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
38
39
40
41
public class Remove_Even_Integers {
public static void printArray(int[] arr){
for(int i = 0; i<arr.length;i++){
System.out.print(arr[i] + " ");
}
System.out.println();
}
public static int[] removeEven(int[] arr){
int oddCount = 0;
for (int i = 0;i<arr.length;i++){
if(arr[i]%2 != 0){
oddCount++;
}
}
int[] result = new int[oddCount];
int idx = 0;
for (int i = 0;i<arr.length;i++){
if(arr[i]%2 != 0){
result[idx] = arr[i];
idx++;
}
}
return result;
}
public static void main(String[] args) {
int[] number = {1,2,3,4,5,6,89,547,45};
System.out.println("Original Array");
printArray(number);
System.out.println("Array after removing even integers");
printArray(removeEven(number));
}
}