SHARE
TWEET

Untitled

a guest Oct 14th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         System.out.print("Enter any number: ");
  9.         int el_number = input.nextInt();
  10.  
  11.         if (el_number <= 0) {
  12.             System.out.println("Not a positive number");
  13.         }
  14.  
  15.         int[] random_array = new int[el_number];
  16.  
  17.  
  18.         for (int i = 0; i < el_number; i++) {
  19.             int rand = (int) (Math.random() * 100);
  20.             random_array[i] = rand;
  21.         }
  22.  
  23.  
  24.         System.out.print("Even: ");
  25.         for (int i=0; i < el_number; i++) {
  26.             if ((random_array[i] % 2) == 0) {
  27.                 System.out.print(random_array[i] + " ");
  28.             }
  29.         }
  30.  
  31.         System.out.println();
  32.         System.out.print("Odd: ");
  33.         for (int i=0; i < el_number; i++) {
  34.             if ((random_array[i] % 2) != 0) {
  35.                 System.out.print(random_array[i] + " ");
  36.             }
  37.         }
  38.  
  39.         System.out.println();
  40.         System.out.print("Can be divided by 3: ");
  41.         for (int i=0; i < el_number; i++) {
  42.             if ((random_array[i] % 3) == 0) {
  43.                 System.out.print(random_array[i] + " ");
  44.             }
  45.         }
  46.  
  47.         System.out.println();
  48.         System.out.print("Can be divided by 5: ");
  49.         for (int i=0; i < el_number; i++) {
  50.             if ((random_array[i] % 5) == 0) {
  51.                 System.out.print(random_array[i] + " ");
  52.             }
  53.         }
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top