Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DrawFort {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- int leftRight = n / 2;
- int middle = 2 * (n - leftRight - 2);
- System.out.printf("/%s\\%s/%s\\\n",
- repeatChar(leftRight, '^'),
- repeatChar(middle, '_'),
- repeatChar(leftRight, '^')
- );
- int height = n - 2;
- int inside = 2 * n - 2;
- for (int i = 0; i < height; i++) {
- if(i == height - 1){
- leftRight++;
- System.out.printf("|%s%s%s|\n",
- repeatChar(leftRight, ' '),
- repeatChar(middle, '_'),
- repeatChar(leftRight, ' ')
- );
- }
- else{
- System.out.printf("|%s|\n",
- repeatChar(inside, ' '));
- }
- }
- leftRight--;
- System.out.printf("\\%s/%s\\%s/\n",
- repeatChar(leftRight, '_'),
- repeatChar(middle, ' '),
- repeatChar(leftRight, '_')
- );
- }
- private static String repeatChar(int n, char ch){
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < n; i++) {
- sb.append(ch);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement