Didart

Refactoring Prime Checker

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