Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  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. while (el_number <= 0) {
  12. System.out.print("Please input any positive number: ");
  13. el_number = input.nextInt();
  14. }
  15.  
  16. int[] random_array = new int[el_number];
  17.  
  18.  
  19. for (int i = 0; i < el_number; i++) {
  20. int rand = (int) (Math.random() * 100);
  21. random_array[i] = rand;
  22. }
  23.  
  24.  
  25. System.out.print("Even: ");
  26. for (int i=0; i < el_number; i++) {
  27. if ((random_array[i] % 2) == 0) {
  28. System.out.print(random_array[i] + " ");
  29. }
  30. }
  31.  
  32. System.out.println();
  33. System.out.print("Odd: ");
  34. for (int i=0; i < el_number; i++) {
  35. if ((random_array[i] % 2) != 0) {
  36. System.out.print(random_array[i] + " ");
  37. }
  38. }
  39.  
  40. System.out.println();
  41. System.out.print("Can be divided by 3: ");
  42. for (int i=0; i < el_number; i++) {
  43. if ((random_array[i] % 3) == 0) {
  44. System.out.print(random_array[i] + " ");
  45. }
  46. }
  47.  
  48. System.out.println();
  49. System.out.print("Can be divided by 5: ");
  50. for (int i=0; i < el_number; i++) {
  51. if ((random_array[i] % 5) == 0) {
  52. System.out.print(random_array[i] + " ");
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement