SvetlanPetrova

Prime Checker SoftUni

Jun 12th, 2021
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RefactoringPrimeChecker {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.  
  10.         for (int i = 2; i <= n; i++) {
  11.             boolean check = true;
  12.             for (int j = 2; j <= Math.sqrt(i); j ++) {
  13.                 if (i % j == 0) {
  14.                     check = false;
  15. //                    break;
  16.                 }
  17.             }
  18.             System.out.printf("%d -> %b%n", i, check);
  19.         }
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment