Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PrimeTriangle {
  6.  
  7.  public static void isPrime(int n) {
  8.      for (int i = 1; i <= n; i++) {
  9.          int divider = 2;
  10.          int maxDivider = (int) Math.sqrt(i);
  11.          boolean isPrime = true;
  12.          while (isPrime && divider <= maxDivider) {
  13.              if (i % divider == 0) {
  14.                  isPrime = false;
  15.              }
  16.              divider++;
  17.          }
  18.          for (int j = 0; j <i ; j++) {
  19.              if(isPrime){
  20.              System.out.print("1");}
  21.              else{
  22.                  System.out.print("0");
  23.              }
  24.  
  25.          }  System.out.println();
  26.  
  27.      }
  28.      return ;
  29.  }
  30.  
  31.     public static void main(String[] args) {
  32.         Scanner userInput = new Scanner(System.in);
  33.        int n=userInput.nextInt();
  34.        isPrime(n);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement