Hello everybody,
I recently started learning java and I am having a problem. The code I am writing is supposed to display an hourglass like this. The lines match up so it looks like an hourglass.
|""""""""""| top part
\::::::::/
\::::::/
\::::/ middle part
\::/
|| Vertical
/::\
/::::\ bottom part
/::::::\
/::::::::\
|""""""""""|
but when I run my code I get this. I don't know why I am getting this and it would be very helpful if anyone gave me some advice as to what I can do to make the bottom hourglass look like the top.
|:::::::::
::::::::
::::::
::::
::
||
::
::::
::::::
::::::::
|:::::::::
public class HourGlass { public static void main(String[] args) { topPart(); middlePart(); verticalPart(); bottomPart(); topPart(); } //This method produces the top part of the hourglass public static void topPart() { System.out.print("|"); for (int i =1; i <=10; i++) { System.out.print(":"); } System.out.print("|"); System.out.println(); } //This method produces the middle part of the hourglass public static void middlePart() { for (int line =1; line <=4; line++) { for (int space=1; space<= (line * 2 ); space++) { System.out.print(" "); } for (int semicolon =1; semicolon <= (line * -2 + 10); semicolon++) { System.out.print(":"); } for (int space=1; space <= (line * 2); space++) { System.out.print(" "); } System.out.println(); } } //This method produces the vertical line of the hourglass public static void verticalPart() { for (int space = 1; space <=5; space++) { System.out.print(""); } System.out.print("||"); for (int space = 1; space <=5; space++) { System.out.print(" "); } System.out.println(); } //This method produces the bottom part of the hourglass public static void bottomPart() { for(int line =1; line <=4; line++) { for (int space=1; space <= (line * -2 + 10); space++) { System.out.print(" "); } for (int semicolon =1; semicolon <= (line * 2); semicolon++) { System.out.print(":"); } for (int space=1; space <= (line * 2); space++) { System.out.print(" "); } System.out.println(); } } }