Advertisement
ralitsa_d

DrawFort

Feb 4th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DrawFort {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scan.nextLine());
  8.  
  9. int leftRight = n / 2;
  10. int middle = 2 * (n - leftRight - 2);
  11.  
  12. System.out.printf("/%s\\%s/%s\\\n",
  13. repeatChar(leftRight, '^'),
  14. repeatChar(middle, '_'),
  15. repeatChar(leftRight, '^')
  16. );
  17.  
  18. int height = n - 2;
  19. int inside = 2 * n - 2;
  20.  
  21. for (int i = 0; i < height; i++) {
  22. if(i == height - 1){
  23. leftRight++;
  24. System.out.printf("|%s%s%s|\n",
  25. repeatChar(leftRight, ' '),
  26. repeatChar(middle, '_'),
  27. repeatChar(leftRight, ' ')
  28. );
  29. }
  30. else{
  31. System.out.printf("|%s|\n",
  32. repeatChar(inside, ' '));
  33. }
  34. }
  35.  
  36. leftRight--;
  37. System.out.printf("\\%s/%s\\%s/\n",
  38. repeatChar(leftRight, '_'),
  39. repeatChar(middle, ' '),
  40. repeatChar(leftRight, '_')
  41. );
  42. }
  43.  
  44. private static String repeatChar(int n, char ch){
  45. StringBuilder sb = new StringBuilder();
  46.  
  47. for (int i = 0; i < n; i++) {
  48. sb.append(ch);
  49. }
  50.  
  51. return sb.toString();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement