Advertisement
jamius19

Remove Odd

Oct 20th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. public class array{
  2.     public static int[] removeOdd(int[] arr){
  3.         int count = 0;
  4.        
  5.         for(int c : arr)
  6.             if(c % 2 == 0) count++;
  7.        
  8.         int[] even = new int[count];
  9.        
  10.         for(int x = 0, y = 0; x < even.length; x++){
  11.             for(; y < arr.length; y++){
  12.                 if(arr[y] % 2 == 0){
  13.                     even[x] = arr[y];
  14.                     y++;
  15.                     break;
  16.                 }
  17.             }
  18.         }
  19.        
  20.         return even;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement