Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ex01DrawFort {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int middleSection = Math.max(0, n - 4 + n % 2);
  9.         String northTowers = "/" + new String(new char[n / 2]).replace('\0', '^') + '\\';
  10.         String northWall = northTowers + new String(new char[middleSection]).replace('\0', '_') + northTowers;
  11.  
  12.         char[] middleLines = new char[2 * n];
  13.         for (int i = 1; i < 2 * n - 1; i++) {
  14.             middleLines[i] = ' ';
  15.         }
  16.         middleLines[0] = '|';
  17.         middleLines[2 * n - 1] = '|';
  18.  
  19.         String southTowers = "\\" + new String(new char[n / 2]).replace('\0', '_') + "/";
  20.         String southWall = southTowers + new String(new char[middleSection]).replace('\0', ' ') + southTowers;
  21.  
  22.         for (int i = 0; i < n; i++) {
  23.             if (i == 0) {
  24.                 System.out.println(northWall);
  25.             } else if (i == n - 1) {
  26.                 System.out.println(southWall);
  27.             } else if (i == n - 2) {
  28.                 for (int j = 0; j < middleSection; j++) {
  29.                     middleLines[n - middleSection / 2 + j] = '_';
  30.                 }
  31.                 System.out.println(middleLines);
  32.             } else {
  33.                 System.out.println(middleLines);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement