Advertisement
Guest User

Draw Fort

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