Advertisement
CR7CR7

primeNumber

Apr 5th, 2023
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrimeTriangle {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int n = Integer.parseInt(scan.nextLine());
  7.  
  8.         String output = "";
  9.  
  10.         for (int i = 1; i <= n; i++) {
  11.             boolean isPrime = true;
  12.             for (int j = 2; j <= i - 1 ; j++) {
  13.                 if (i % j == 0){
  14.                     isPrime = false;
  15.                     break;
  16.  
  17.                 }
  18.             }
  19.             if (isPrime) {
  20.                 output += "1";
  21.                 System.out.println(output);
  22.             } else {
  23.                 output += "0";
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement