Advertisement
YavorGrancharov

RhombusOfStars

Feb 12th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RhombusOfStars {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         int n = Integer.parseInt(console.nextLine());
  7.         int spaces = n - 1;
  8.         int stars = 1;
  9.         for (int i = 0; i < n; i++) {
  10.             System.out.println(repeatStr(" ", spaces) + repeatStr("* ", stars));
  11.             spaces--;
  12.             stars++;
  13.         }
  14.         spaces = 1;
  15.         stars -= 2;
  16.         for (int i = 0; i < n; i++) {
  17.             System.out.println(repeatStr(" ", spaces) + repeatStr("* ", stars));
  18.             spaces++;
  19.             stars--;
  20.         }
  21.     }
  22.     static String repeatStr(String str, int count) {
  23.         StringBuilder repeated = new StringBuilder();
  24.         for (int i = 0; i < count; i++) {
  25.             repeated.append(str);
  26.         }
  27.         return repeated.toString();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement