 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sonia Guest
|
Posted: Sat Nov 22, 2003 5:49 pm Post subject: simple code question |
|
|
hey guys, I'm trying to print a simple figure as shown in figure (C):
(A) (B) (C) (D)
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
But i cannot get it to work:
I use the following code,
could you tell me what is wrong with my code ?
Thanks
import javax.swing.JOptionPane;
public class Ex0510 {
public static void main(String args[]) {
int column=0;
String output="";
for(int row = 1; row < 11; row++) {
// output += " * ";
for (column = 1; column < 11; column++) {
if (column >row)
output += " * ";
else if (row >=column)
output +=" ";
}
output +="n";
}
JOptionPane.showMessageDialog(null, output, "Printing *s",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
|
|
| Back to top |
|
 |
Alex Hunsley Guest
|
Posted: Mon Nov 24, 2003 4:07 pm Post subject: Re: simple code question |
|
|
Sonia wrote:
| Quote: | hey guys, I'm trying to print a simple figure as shown in figure (C):
(A) (B) (C) (D)
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
But i cannot get it to work:
I use the following code,
could you tell me what is wrong with my code ?
Thanks
[snip]
|
Erm, it hasn't been finished yet? :)
For a start, your loops which go through the rows and columns: you don't
have the correct number of columns. You've got 10 columns in the code.
Look at your diagram. How many columns are there?
Doing a nested for loop will work ok for what you're trying to do.
For now, concentrate on just getting a picture full of * (i.e. 25 across).
Then when that is working, work on making the stars *not* be printed in
the correct places, such that you have the three stripes appearing.
alex
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|