Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package DrawingFiguresWithLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FortProblem2 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         int width = 2*n;
  10.         int height = n;
  11.  
  12.         // TOP LANE
  13.  
  14.          String horns =repeatStr("^", n/2) ;
  15.          String slash =repeatStr( "_" ,width -( 2*(n/2)) - 4);
  16.  
  17.         System.out.println("/" + horns +"\\" +slash + "/" +horns + "\\");
  18.  
  19.         // Middle
  20.  
  21.         String spacesBetwenWalls = repeatStr(" ", width-2);
  22.         for (int i = 1; i <=n-3 ; i++) {
  23.             System.out.println("|" + spacesBetwenWalls+"|");
  24.         }
  25.         // Before Ground
  26.            String spacesBeforeGround =  repeatStr(" ",n/2+1);
  27.  
  28.         System.out.println( "|"+ spacesBeforeGround +slash + spacesBeforeGround+"|" );
  29.  
  30.         // Ground Level
  31.         String ground = repeatStr("_",n/2);
  32.         String spacesOnGround = repeatStr(" ",width -( 2*(n/2)) - 4);
  33.  
  34.         System.out.println("\\"+ground + "/"+spacesOnGround+"\\"+ground+"/");
  35.     }
  36.     static String repeatStr(String str, int count) {
  37.         String text = "";
  38.         for (int i = 0; i < count; i++) {
  39.             text += str;
  40.         }
  41.         return text;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement