Hi, my name is Courtney and I'm a bit new to Java. I'm trying to do a few exercises but I'm getting stuck.
Here is the first one.
Write for loops to produce the following output:
*
**
***
****
*****
Printable View
Hi, my name is Courtney and I'm a bit new to Java. I'm trying to do a few exercises but I'm getting stuck.
Here is the first one.
Write for loops to produce the following output:
*
**
***
****
*****
You'll need two loops, the outer for the number of lines you want to print.
The inner one for printing the number of *s on that line.
Do you see the relationship between the line number and the number of *s on that line?
There is another cheap way of doing so. Use five print statements each one with different number of *s. I am not trying to do this for you but consider the fact that you have 1 * in the first row, 2, 3, 4, 5 consecutively. You also have 5 columns. Play around the two for-loops and you will be better at it.