YavorGrancharov

ExamTask5(Hourglass)

Mar 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamTask5 {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         int n = Integer.parseInt(console.nextLine());
  7.  
  8.         int width = 2 * n + 1;
  9.         int height = 2 * n + 1;
  10.         int dotsIn = 2;
  11.         int dotsout = 2;
  12.         int symbol = n + n - 5;
  13.         //int asterisks = 0;
  14.  
  15.         for (int i = 0; i < 1; i++) {
  16.             System.out.println(repeatStr("*", width));
  17.             System.out.println("." + "*" + repeatStr(" ", width - 4) + "*" + ".");
  18.         }
  19.  
  20.         for (int i = 3; i <= n; i++) {
  21.             System.out.println(repeatStr(".", dotsIn) + "*" + repeatStr("@", symbol) + "*" + repeatStr(".", dotsout));
  22.             dotsIn++;
  23.             symbol-=2;
  24.             dotsout++;
  25.         }
  26.  
  27.         for (int i = 0; i < 1; i++) {
  28.             System.out.println(repeatStr(".", n) + "*" + repeatStr(".", n));
  29.  
  30.         }
  31.  
  32.         int spaceIn = 0;
  33.         int spaceOut = 0;
  34.         for (int i = 3; i <= n; i++) {
  35.             System.out.println(repeatStr(".", dotsIn - 1) + "*" + repeatStr(" ", spaceIn) + "@" + repeatStr(" ", spaceOut) + "*" + repeatStr(".", dotsout - 1));
  36.             dotsIn--;
  37.             spaceIn++;
  38.             spaceOut++;
  39.             dotsout--;
  40.         }
  41.  
  42.         for (int i = 0; i < 1; i++) {
  43.             System.out.println("." + "*" + repeatStr("@", width - 4) + "*" + ".");
  44.             System.out.println(repeatStr("*", width));
  45.         }
  46.     }
  47.  
  48.     static String repeatStr(String str, int count) {
  49.         StringBuilder repeated = new StringBuilder();
  50.         for (int i = 0; i < count; i++) {
  51.             repeated.append(str);
  52.         }
  53.         return repeated.toString();
  54.     }
  55. }
Add Comment
Please, Sign In to add comment