AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

simple code question

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Sonia
Guest





PostPosted: Sat Nov 22, 2003 5:49 pm    Post subject: simple code question Reply with 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

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





PostPosted: Mon Nov 24, 2003 4:07 pm    Post subject: Re: simple code question Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.