Friday, 27 September 2013

I can ONLY use the "for" loop

I can ONLY use the "for" loop

How do I get an output like this? Use one and only one for loop to print
the following pattern in one dialog box. Do not use nested for loops. Use
only one for loop, not two or more. Do not use any other kind of loop. Do
not use a switch/case statement or if conditions. The same code should
work for 7 lines of asterisks or 17 lines of asterisks, simply by changing
the number of times the loop executes, from 7 to 17.
*
**
***
****
*****
******
*******
My code gives me this:
*
*
*
*
*
*
*
Here's my code:
String message7;
message7 = "";
for (count = 0; count < 8; count = count + 1)
{
message7 = message7 + "*\n";
}
JOptionPane.showMessageDialog(null,message7);

No comments:

Post a Comment