Advertisement
YavorGrancharov

Diamond2

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