Advertisement
didatzi

Fort

Feb 14th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class e05_DrawFort {
  4.     private static String repeat(String strToRepeat, int count) {
  5.         String text = "";
  6.         for (int i = 0; i < count; i++) {
  7.             text = text + strToRepeat;
  8.         }
  9.         return text;
  10.     }
  11.  
  12.     public static void main(String[] args) {
  13.         Scanner scanner = new Scanner(System.in);
  14.         int n = Integer.parseInt(scanner.nextLine());
  15.         String base = "\\" + repeat("_", n / 2) + "/";
  16.         String top = "/" + repeat("^", n / 2) + "\\";
  17.         if (n < 5) {
  18.  
  19.             System.out.println(top + top);
  20.         } else {
  21.             System.out.println(top + repeat("_", n / 2) + top);
  22.  
  23.         }
  24.         for (int i = 0; i < n - 2; i++) {
  25.             if (n < 5) {
  26.                 System.out.println("|" + repeat(" ", 3 * n / 2) + "|");
  27.             } else if (n % 2 == 0) {
  28.                 if (i == n - 3) {
  29.                     System.out.println("|" + repeat(" ", n / 2 + 1)
  30.                             + repeat("_", n / 2) +
  31.                             repeat(" ", n / 2 + 1) + "|");
  32.                 } else {
  33.                     System.out.println("|" + repeat(" ", (3 * n / 2) + 2) + "|");
  34.                 }
  35.             } else if (n % 2 != 0) {
  36.                 if (i == n - 3) {
  37.                     System.out.println("|" + repeat(" ", n / 2 + 1)
  38.                             + repeat("_", n / 2) +
  39.                             repeat(" ", n / 2 + 1) + "|");
  40.                 } else {
  41.                     System.out.println("|" + repeat(" ", (3 * n / 2) + 1) + "|");
  42.                 }
  43.             }
  44.         }
  45.         if (n < 5) {
  46.  
  47.             System.out.println(base + base);
  48.         } else {
  49.             System.out.print(base + repeat(" ", n / 2) + base);
  50.  
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement