Advertisement
DanikYakush

Task23

Jul 5th, 2022
791
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Task23 {
  5.     static int var = 2;
  6.     public static void main(String[] args) {
  7.         int n, k;
  8.         Random rand = new Random();
  9.         Scanner in = new Scanner(System.in);
  10.         n = in.nextInt();
  11.         k = in.nextInt();
  12.         int[] array = new int[n];
  13.         for (int i = 0; i < n; i++) {
  14.             array[i] = rand.nextInt(1, 100);
  15.             if(checkIsItANaturalNumber(i)) System.out.println(array[i]);
  16.         }
  17.  
  18.     }
  19.     private static boolean checkIsItANaturalNumber(int n) {
  20.         if (n > 1) {
  21.             if (n % var != 0) {
  22.                 var++;
  23.                 checkIsItANaturalNumber(n);
  24.             } else if (n % var == 0) {
  25.                 if(n == var) return true;
  26.             }
  27.         }
  28.         return false;
  29.     }
  30. }
  31.  
Advertisement
RAW Paste Data Copied
Advertisement