I thought I knew how loops worked drawing memory until I got this assignment with JOptionPane. Please read the following.
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.
*
**
***
****
*****
******
*******
This is what I have put down
String message = "";
int i;
for(i = 0; i < 7; i++)
{
message += "*";
JOptionPane.showMessageDialog(null, message);
}
putting JOptionPane inside of the loop will get you 7 JOption boxes with the asterisk incrementing each time. If I put it outside of the loop I will get on box, but 7 asterisks in a row. Now adding a \n to the end of the asterisk will give me 7 asterisks in a row of 1 and a column of seven. How in the world do I get this asterisk to increment in one JOption box? Hints, programing logic, sites, anything that can help is much appreciated!
trial 2.
String message = "";
int i;
for(i = 0; i < 7; i++)
{
message += "*";
}
JOptionPane.showMessageDialog(null, message);
you get one box
*******
trial 3
String message = "";
int i;
for(i = 0; i < 7; i++)
{
message += "*\n";
}
JOptionPane.showMessageDialog(null, message);
*
*
*
*
*
*
*
I have tried all sorts of things, but when I write out the memory on a piece of paper, I get stuck. If this was command line, this wouldn't be an issue!
Thank You for your time,