Advertisement
Boyan5

Cikli

Apr 8th, 2020
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class suns {
  4.  
  5.     public static void main (String [] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int stars = 0;
  11.         if(n % 2 == 0) {
  12.             stars = 2;
  13.         }else{
  14.             stars = 1;
  15.         }
  16.         for (int i = 0; i  < Math.ceil(n / 2.0) ; i++) {
  17.             String row =
  18.                     repeatStr("_",(n - stars) / 2 )
  19.                       + repeatStr("*",stars)
  20.                      +repeatStr("_",(n - stars) / 2);
  21.  
  22.             stars += 2;
  23.             System.out.println(row);
  24.         }
  25.         for (int i = 0; i < n / 2; i++) {
  26.              String row = "|" + repeatStr("*",n-2) + "|";
  27.             System.out.println(row);
  28.         }
  29.  
  30.     }
  31.  
  32. static String repeatStr(String strToRepeat, int count ) {
  33.         String text = "";
  34.     for (int i = 0; i < count ; i++) {
  35.         text = text + strToRepeat;
  36.     }
  37.     return strToRepeat;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement