^^ I hope thats not a school assignment.
Anyways, the logic is pretty simple.
(1) Have an outer loop iterate thru 0 to 4. End it with System.out.println().
(2) Have an inner loop iterate through 0 till i and print a single *.
The above steps will give you the first part of the pattern. Reverse the logic to get the lower half.
- Bandu.
P.S. There are other ways to do this and there might be more simpler ways as well.
Edit: The thread subscription email that I received has a different pattern. If it is the exact opposite of whats seen in the thread, then u'll have to slightly modify the loop structures:
Anyways, the logic is pretty simple.
(1) Have an outer loop iterate thru 0 to 4. End it with System.out.println().
(2) Have an inner loop iterate through 0 till i and print a single *.
The above steps will give you the first part of the pattern. Reverse the logic to get the lower half.
- Bandu.
P.S. There are other ways to do this and there might be more simpler ways as well.
Code:
for(int i = 0; i < 4; i++, System.out.println())
for(int j = 0; j <= i; j++)
System.out.print("*");
Edit: The thread subscription email that I received has a different pattern. If it is the exact opposite of whats seen in the thread, then u'll have to slightly modify the loop structures:
Code:
for(int i = 0; i < 4; i++, System.out.println())
{
for(int j = 4; j > i; j--)
System.out.print(" ");
for(int k = 0; k <= i; k++)
System.out.print("*");
}
Last edited: