Advertisement
H0_0H

Untitled

Feb 2nd, 2023
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4.  
  5. public class PrimeCalculatot {
  6.     public static boolean isPrime(int n){
  7.         for (int i = 2; i <= (int)Math.sqrt(n); i++){
  8.             if (n % i == 0)
  9.                 return false;
  10.         }
  11.         return true;
  12.     }
  13.  
  14.     public static void main(String[] args){
  15.         int n;
  16.         Scanner sc = new Scanner(System.in);
  17.         n = sc.nextInt();
  18.         for (int i = 2; i <= n; i++){
  19.             if (isPrime(i))
  20.                 System.out.println(i);
  21.         }
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement