Skip to content
Advertisement

Creating a border with System.out.println()

Is there anyway to create this sort of arrangement, without the String variable sh3 affecting the border? I’m really stumped here, my Java knowledge is pretty much limited to what you see here if that helps?

System.out.println("###################################################"); 
System.out.println("#    **** WEST END THEATRE BOOKING SYSTEM ****    #"); 
System.out.println("#                                                 #"); 
System.out.println("#                 T I C K E T                     #"); 
System.out.println("#                                                 #"); 
System.out.println("#     Show:    "+sh3+"                            #"); 
System.out.println("#     Theatre: Her Majesty's                      #"); 
System.out.println("#     Price:   65                                 #"); 
System.out.println("###################################################");

Advertisement

Answer

I know I am not providing the code for this, but I am pointing to the process of thinking and then leaving implementation to you.

There are 4 properties in play, out of which you know the total size of line, also you know the length of the string and you know how much space is to be left can be easily found.

And all you will need is a loop that will calculate how much spaces should be left.

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement