borkins

Exam 06-Mar-2016 - 05. Draw Fort

May 14th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. /**
  2.  * Project: Exam_06_March_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _05_DrawFort
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.    
  13.         int n = Integer.parseInt(console.nextLine());
  14.    
  15.         String columnTop = "/" + new String(new char[n / 2]).replace("\0", "^") + "\\";
  16.         String columnBottom = "\\" + new String(new char[n / 2]).replace("\0", "_") + "/";
  17.         String centralBond = new String(new char[2 * (n - n / 2) - 4]).replace("\0", "_");
  18.         String centralSpace = centralBond.replace("_", " ");
  19.    
  20.         int width = 2 * columnTop.length() + centralBond.length() - 2;
  21.    
  22.         System.out.println(columnTop + centralBond + columnTop);
  23.    
  24.         for (int row = 0; row < n - 2; row++)
  25.         {
  26.             System.out.print("|");
  27.             for (int col = 0; col < width; col++) {
  28.                 System.out.print(" ");
  29.            
  30.                 if (row == n - 3 && col == n / 2) {
  31.                     System.out.print(centralBond);
  32.                     col += centralBond.length();
  33.                 }
  34.             }
  35.             System.out.println("|");
  36.         }
  37.         System.out.println(columnBottom + centralSpace + columnBottom);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment