Draxion

EvenAndOdd

Nov 21st, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class EvenandOdd {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner ask = new Scanner(System.in);
  7.         System.out.print("Enter a number: ");
  8.         int ans = ask.nextInt();
  9.         Random rnd = new Random();
  10.  
  11.         int[] al = new int[9];
  12.  
  13.         for (int n = 0; n < al.length; n++) {
  14.             int nums = rnd.nextInt(100) + 1;
  15.             al[n] = nums;
  16.         }
  17.         Arrays.sort(al);
  18.         System.out.print("\nEvens: ");
  19.         for (int z : al) {
  20.             if (z % 2 == 0) {
  21.                 System.out.print(z + " ");
  22.             }
  23.  
  24.         }
  25.         System.out.print("\nOdds: ");
  26.         for (int y : al) {
  27.             if (y % 2 == 1) {
  28.                 System.out.print(y + " ");
  29.             }
  30.         }
  31.         if (Arrays.binarySearch(al, ans) >= 0) {
  32.             System.out.print("\nYour number is in the array.");
  33.         } else {
  34.             System.out.print("\nYour number is not in the array.");
  35.         }
  36.  
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment