Advertisement
Guest User

Untitled

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