Guest User

Fort

a guest
Feb 20th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Jo on 2/20/2017.
  5.  */
  6. public class DrawFort {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int fortSize = Integer.parseInt(scanner.nextLine());
  10.         int halfFortSize = fortSize / 2;
  11.  
  12. // First row
  13.         System.out.print("/" + draw("^", halfFortSize) + "\\");
  14.         if (fortSize % 2 != 0) {
  15.             System.out.print(draw("_", fortSize - 3));
  16.         } else {
  17.             System.out.print(draw("_", fortSize - 4));
  18.         }
  19.         System.out.println("/" + draw("^", halfFortSize) + "\\");
  20.  
  21. //Middle rows
  22.         for (int i = 0; i < fortSize - 3; i++) {
  23.             System.out.println("|" + draw(" ", 2 * fortSize - 2) + "|");
  24.         }
  25.  
  26. //Before last row
  27.         System.out.print("|" + draw(" ", halfFortSize + 1));
  28.         if (fortSize % 2 != 0) {
  29.             System.out.print(draw("_", fortSize - 3));
  30.         } else {
  31.             System.out.print(draw("_", fortSize - 4));
  32.         }
  33.         System.out.println(draw(" ", halfFortSize + 1) + "|");
  34.  
  35. //Last row
  36.         System.out.print("\\" + draw("_", halfFortSize) + "/");
  37.         if (fortSize % 2 != 0) {
  38.             System.out.print(draw(" ", fortSize - 3));
  39.         } else {
  40.             System.out.print(draw(" ", fortSize - 4));
  41.         }
  42.         System.out.println("\\" + draw("_", halfFortSize) + "/");
  43.  
  44.     }
  45.  
  46.     public static String draw(String str, int count) {
  47.         StringBuilder sb = new StringBuilder();
  48.  
  49.         for (int i = 0; i < count; i++) {
  50.             sb.append(str);
  51.         }
  52.         return sb.toString();
  53.     }
  54.  
  55. }
Add Comment
Please, Sign In to add comment