# need help printing hourglass shape

• August 26th, 2014, 10:50 AM
valium123
need help printing hourglass shape
I am only able to print upper half of the hourglass. Please help with the ower half.
Code :

```public static void printHourglass(int size, char symbol) { int count = 0; int count2 = 0; boolean lower = false; for(int lines = 0; lines < size; lines++) { //upper half   for(int spaces = 0; spaces < lines; spaces++) { if(lower == false) System.out.print(" "); else break;   } count = 0; for(int j = lines; j <= size - (lines + 1); j++) { count++; System.out.print(symbol);   }     for(int spaces = 0; spaces < lines;spaces++) { if(lower == false) System.out.print(" "); else break;     } System.out.println("");       }       }```
• August 26th, 2014, 12:36 PM
KevinWorkman
Re: need help printing hourglass shape
We can't run this code because it isn't in the form of an MCVE.

What have you tried? What exactly are you confused about? We aren't just going to do your homework for you.
• August 26th, 2014, 03:36 PM
GregBrannon
Re: need help printing hourglass shape
If you've successfully coded the top half, why can't you reverse the logic to print the lower half? Similar to:

A
B
C
C
B
A
• August 26th, 2014, 04:29 PM
valium123
Re: need help printing hourglass shape
This is not homework. I am trying to teach myself java.

This code is supposed to print symbols in hourglass shape.
size must be an odd number. For example giving it a parameter of 3 and 'Q' should print

Quote:

QQQ
Q
QQQ

I'm able to print the first two lines but not the third.
• August 26th, 2014, 04:33 PM
Norm
Re: need help printing hourglass shape
Quote:

but not the third.
Can you explain what the problem is printing the third line? For that simple example the third line is the same as the first line.
Look at the post#3. Think about how the line lengths shorten and then lengthen.
• August 26th, 2014, 04:50 PM
valium123
Re: need help printing hourglass shape
This is not homework. I am trying to teach myself java.

This code is supposed to print symbols in hourglass shape.
size must be an odd number. For example giving it a parameter of 3 and 'Q' should print

Code :

```QQQ Q QQQ```

I'm able to print the first two lines but not the third.
• August 26th, 2014, 05:22 PM
Norm
Re: need help printing hourglass shape
Quote:

but not the third.
Please explain what the problem is.

For the 3 lines you've shown:
set cnt=3
set change to -2
print cnt Qs
cnt = cnt + change
print cnt Qs
now set change to +2 -> to add 2 to cnt instead of subtracting 2

Put the above in a loop to print the total lines