martinvalchev

Rhombus Of Stars

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