Advertisement
Spocoman

04. Refactoring: Prime Checker

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