vpaleshnikov

DrawFort

Apr 13th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class practice {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7. String top = repeatStr("/", (n + 1) - n) + repeatStr("^", n / 2) + repeatStr("\\", (n + 1) - n);
  8.  
  9. if (n < 3 || n > 1000){
  10. System.out.println("Wrong input!");
  11. return;
  12. }
  13. if (n < 5) {
  14. System.out.println(top + top);
  15. } else {
  16. System.out.println(top + repeatStr("_", n / 2) + top);
  17. }
  18.  
  19. for (int i = 0; i < (n - 2) - 1; i++) {
  20. if (n < 5){
  21. System.out.println("|" + repeatStr(" ",n-1) + repeatStr(" ",n-1) + "|");
  22.  
  23. } else {
  24. System.out.print("|" + repeatStr(" ",n/ 2));
  25. System.out.print(repeatStr(" ",n / 2));
  26. System.out.println(repeatStr(" ",(n/2)+2) + "|");
  27.  
  28. }
  29.  
  30. }
  31. String midBottom = repeatStr("_", n / 2);
  32. if (n < 5){
  33. System.out.println("|" + repeatStr(" ",(n/2)+1)+ repeatStr(" ",(n/2)+1) + "|");
  34. } else {
  35. System.out.println("|" + repeatStr(" ",(n +2)/2) + midBottom + repeatStr(" ",(n+2)/2) + "|");
  36. }
  37.  
  38. String floor = "\\" + repeatStr("_", (n / 2)) + "/";
  39.  
  40. if (n < 5) {
  41. System.out.println(floor + floor);
  42. } else {
  43. System.out.println(floor + repeatStr(" ", n / 2) + floor);
  44. }
  45. }
  46. static String repeatStr(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. }
Advertisement
Add Comment
Please, Sign In to add comment