Advertisement
Angel_Kalinkov

PBE-17December2017-ChristmasSock_AngelKalinkov

Mar 2nd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ChristmassSock {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         System.out.printf("|%s|%n", partOfRow("-", 2 * n));
  10.         System.out.printf("|%s|%n", partOfRow("*", 2 * n));
  11.         System.out.printf("|%s|%n", partOfRow("-", 2 * n));
  12.  
  13.         for (int i = 0; i < n - 1; i++) {
  14.             System.out.printf("|%s%s%s|%n", partOfRow("-", n - 1 - i ),
  15.                     partOfRow("~", i * 2 + 2), partOfRow("-", n - 1 - i ));
  16.         }
  17.         for (int i = n - 2; i > 0; i--) {
  18.             System.out.printf("|%s%s%s|%n", partOfRow("-", n - i ),
  19.                     partOfRow("~", i * 2), partOfRow("-", n - i ));
  20.         }
  21.         for (int i = 0; i < n + 3 - 1; i++) {
  22.             if (i == n / 2) {
  23.                 System.out.printf("%s\\%sMERRY%s\\%n", partOfRow("-", i), partOfRow(".", n - 2),
  24.                         partOfRow(".", n - 2));
  25.             } else if (i == n / 2 + 2) {
  26.                 System.out.printf("%s\\%sX-MAS%s\\%n", partOfRow("-", i), partOfRow(".", n - 2),
  27.                         partOfRow(".", n - 2));
  28.             } else {
  29.                 System.out.printf("%s\\%s\\%n", partOfRow("-", i), partOfRow(".", 2 * n + 1));
  30.             }
  31.         }
  32.         System.out.printf("%s\\%s)%n", partOfRow("-", n + 2), partOfRow("_", 2 * n + 1));
  33.     }
  34.  
  35.     private static String partOfRow(String symbol, int count) {
  36.         StringBuilder stringBuilder = new StringBuilder();
  37.         for (int i = 0; i < count; i++) {
  38.             stringBuilder.append(symbol);
  39.         }
  40.         return stringBuilder.toString();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement