Advertisement
Shavit

P. 45 Ex. 10.33

Jan 4th, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class OddEvenArray {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int length;
  14.         int i = 0, j = 0;
  15.        
  16.         System.out.printf("Enter the number of numbers you would like to input:\n");
  17.         length = in.nextInt();
  18.        
  19.         int[] even = new int[length];
  20.         int[] odd = new int[length];
  21.        
  22.         System.out.printf("Keep entering numbers:\n");
  23.        
  24.         while((i < length) && (j < length))
  25.         {
  26.             if(in.nextInt() % 2 == 0)
  27.             {
  28.                 even[i] = in.nextInt();
  29.                 i++;
  30.             }
  31.             else
  32.             {
  33.                 odd[j] = in.nextInt();
  34.                 j++;
  35.             }
  36.         }
  37.         System.out.printf("Your even numbers are:\n");
  38.        
  39.         for(int k = 0; k < i; k++)
  40.             System.out.printf("%d", even[k]);
  41.        
  42.         System.out.printf("Your odd numbers are:\n");
  43.        
  44.         for(int k = 0; k < j; k++)
  45.             System.out.printf("%d", even[k]);
  46.        
  47.         in.close();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement