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 FOR LOOP

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





PostPosted: Sun Nov 23, 2003 2:34 am    Post subject: Simple FOR LOOP Reply with quote



Sorry, my posts are not descriptive I guess..
What I am trying to do is to get the histogram below. But the code
does not produce that. Please let me know how can I fix it so I can achieve
the figure below.
Thank You




(C)
**********
*********
********
*******
******
*****
****
***
**
*



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
Anthony Borla
Guest





PostPosted: Sun Nov 23, 2003 5:10 am    Post subject: Re: Simple FOR LOOP Reply with quote



"Sonia" <smach02 (AT) hotmail (DOT) com> wrote

Quote:

Sorry, my posts are not descriptive I guess..
What I am trying to do is to get the histogram below.
But the code does not produce that. Please let me know
how can I fix it so I can achieve the figure below.
Thank You


You can obtain all four variations [(A) through (D)] of the 'triangle'
shapes by varying the 'if' test conditions made in your inner loop:

for (int row = 1; row < TOTALROWS; row++)
{
for (column = 1; column < TOTALROWS; column++)
{
if (...)
// Append either space or '*'
else

// Append either space or '*'
...

After posting my correction I actually found a simpler test condition for
(C), and those for the other shapes are only variations on this.

May I suggest two things:

* Manually compute the values of 'column' and 'row' to
determine the behaviour needed to draw the required
shape

* Use:

System.out.println(output);

in place of 'JOptionPane.showMessageDialog' because
it will give you a truer indication of the shape being
drawn.

Sadly, 'JOptionPane.showMessageDialog' will give a
misleading representation of the some shapes due to
the presence of proportional fonts

Since this appears to be a homework assignment, something undertaken for
your educational benefit, it is best that you try to complete it by
yourself. Some helpful hints have already been provided - the onus is now on
you to apply these suggestions and create a workable solution.

I hope this helps.

Anthony Borla



Back to top
Sonia
Guest





PostPosted: Sun Nov 23, 2003 4:48 pm    Post subject: Re: Simple FOR LOOP Reply with quote




"Anthony Borla" <ajborla (AT) bigpond (DOT) com> wrote

Quote:
"Sonia" <smach02 (AT) hotmail (DOT) com> wrote in message
news:rSVvb.7657$6c3.6234 (AT) bignews1 (DOT) bellsouth.net...

Sorry, my posts are not descriptive I guess..
What I am trying to do is to get the histogram below.
But the code does not produce that. Please let me know
how can I fix it so I can achieve the figure below.
Thank You


You can obtain all four variations [(A) through (D)] of the 'triangle'
shapes by varying the 'if' test conditions made in your inner loop:

for (int row = 1; row < TOTALROWS; row++)
{
for (column = 1; column < TOTALROWS; column++)
{
if (...)
// Append either space or '*'
else

// Append either space or '*'
...

After posting my correction I actually found a simpler test condition for
(C), and those for the other shapes are only variations on this.

May I suggest two things:

* Manually compute the values of 'column' and 'row' to
determine the behaviour needed to draw the required
shape

* Use:

System.out.println(output);

in place of 'JOptionPane.showMessageDialog' because
it will give you a truer indication of the shape being
drawn.

Sadly, 'JOptionPane.showMessageDialog' will give a
misleading representation of the some shapes due to
the presence of proportional fonts

Since this appears to be a homework assignment, something undertaken for
your educational benefit, it is best that you try to complete it by
yourself. Some helpful hints have already been provided - the onus is now
on
you to apply these suggestions and create a workable solution.

I hope this helps.

Anthony Borla



Thanks Anthony,
That hells a lot. As a matter of fact I was trying to figure out why the
figures were a bit "crooked"
when they were displayed. Like you've said I believe it was due to the
'JOptionPane.showMessageDialog'.

Thank You again, you were a big help.



Back to top
Sonia
Guest





PostPosted: Sun Nov 23, 2003 4:53 pm    Post subject: Re: Simple FOR LOOP - Not Homework Reply with quote


"Anthony Borla" <ajborla (AT) bigpond (DOT) com> wrote

Quote:
"Sonia" <smach02 (AT) hotmail (DOT) com> wrote in message
news:rSVvb.7657$6c3.6234 (AT) bignews1 (DOT) bellsouth.net...

Sorry, my posts are not descriptive I guess..
What I am trying to do is to get the histogram below.
But the code does not produce that. Please let me know
how can I fix it so I can achieve the figure below.
Thank You


You can obtain all four variations [(A) through (D)] of the 'triangle'
shapes by varying the 'if' test conditions made in your inner loop:

for (int row = 1; row < TOTALROWS; row++)
{
for (column = 1; column < TOTALROWS; column++)
{
if (...)
// Append either space or '*'
else

// Append either space or '*'
...

After posting my correction I actually found a simpler test condition for
(C), and those for the other shapes are only variations on this.

May I suggest two things:

* Manually compute the values of 'column' and 'row' to
determine the behaviour needed to draw the required
shape

* Use:

System.out.println(output);

in place of 'JOptionPane.showMessageDialog' because
it will give you a truer indication of the shape being
drawn.

Sadly, 'JOptionPane.showMessageDialog' will give a
misleading representation of the some shapes due to
the presence of proportional fonts

Since this appears to be a homework assignment, something undertaken for
your educational benefit, it is best that you try to complete it by
yourself. Some helpful hints have already been provided - the onus is now
on
you to apply these suggestions and create a workable solution.

I hope this helps.

Anthony Borla



Hey Anthony, also, one more comment, these were not homework assignments. I
think it would be little
late to learn FOR loops that late into the semester Smile
Actually I am learning JAVA for myself, I think it will come handy for me
both in workplace as well as my schoolwork.

I would also like to ask you if you knew any good books for JAVA beginners.
Right now I am using DEITEL & DEITEL - JAVA How to Program - I am using 4th
edition, I know 5th out is out.
Have you had an experience with this book - what did you think of
it....Also, any other recommendations as far as books go..

I appreciate it in advance
Sonia



Back to top
Anthony Borla
Guest





PostPosted: Sun Nov 23, 2003 8:55 pm    Post subject: Re: Simple FOR LOOP - Not Homework Reply with quote


"Sonia" <smach02 (AT) hotmail (DOT) com> wrote

Quote:

"Anthony Borla" <ajborla (AT) bigpond (DOT) com> wrote in message
news:xjXvb.23074$aT.19611 (AT) news-server (DOT) bigpond.net.au...
"Sonia" <smach02 (AT) hotmail (DOT) com> wrote in message
news:rSVvb.7657$6c3.6234 (AT) bignews1 (DOT) bellsouth.net...

Sorry, my posts are not descriptive I guess..
What I am trying to do is to get the histogram below.
But the code does not produce that. Please let me know
how can I fix it so I can achieve the figure below.
Thank You


Hey Anthony, also, one more comment, these were not
homework assignments. I think it would be little
late to learn FOR loops that late into the semester :)

Actually I am learning JAVA for myself, I think it will come
handy for me both in workplace as well as my schoolwork.

I would also like to ask you if you knew any good books for
JAVA beginners.

Right now I am using DEITEL & DEITEL - JAVA How to
Program - I am using 4th edition, I know 5th out is out.
Have you had an experience with this book - what did you
think of it....Also, any other recommendations as far as books go..


I'm not familiar with this particular beginner / intermediate-level text
book, though I do know that their 'How to Program in C++' is quite
comprehensive, and generally well regarded, thus would expect their Java
offering to be, similarly, of a high quality.

I can't offer any text book recommendations, just pointers to online
resources:

* Java Sun Tutorial(s):

http://java.sun.com/docs/books/tutorial/index.html

* Bruce Eckel's 'Thinking in Java'

* Web sites like:

http://mindprod.com/jgloss/jgloss.html

I hope this helps.

Anthony Borla



Back to top
David Postill
Guest





PostPosted: Sun Nov 23, 2003 8:59 pm    Post subject: Re: Simple FOR LOOP - Not Homework Reply with quote

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <eq6wb.30259$ow5.11766 (AT) bignews2 (DOT) bellsouth.net>, on Sun, 23 Nov 2003 11:53:30 -0500,
"Sonia"
<smach02 (AT) hotmail (DOT) com> wrote:

<snip />

Quote:
I would also like to ask you if you knew any good books for JAVA beginners.

<snip />

If you don't mind reading books online (or offline on a screen), then you could
try the following:

Beginner:

"Thinking in Java"
<http://mindview.net/Books> see <http://mindview.net/Books/TIJ/NiceComments.html> for comments

Intermediate/Advanced:

"InterfaceDesign"
<http://www.artima.com/interfacedesign/contents.html>

"Hacking Java"
<http://www.wutka.com/hackingjava/>

Cheers,

<davidp />

- --
David Postill

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370

iQA/AwUBP8EbaXxp7q1nhFwUEQJDvgCgx0QEepVwrNRetKFoI9hMPXpM6FcAoMY6
rPINw191LPFFb3zkkmnILYRU
=fPR2
-----END PGP SIGNATURE-----


Back to top
Sonia
Guest





PostPosted: Sun Nov 23, 2003 10:49 pm    Post subject: Thanks Anthony and David these are good start points for me Reply with quote


"David Postill" <david (AT) postill (DOT) org.uk> wrote

Quote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <eq6wb.30259$ow5.11766 (AT) bignews2 (DOT) bellsouth.net>, on Sun, 23 Nov
2003 11:53:30 -0500,
"Sonia"
[email]smach02 (AT) hotmail (DOT) com[/email]> wrote:

snip /

| I would also like to ask you if you knew any good books for JAVA
beginners.

snip /

If you don't mind reading books online (or offline on a screen), then you
could
try the following:

Beginner:

"Thinking in Java"
http://mindview.net/Books> see
http://mindview.net/Books/TIJ/NiceComments.html> for comments

Intermediate/Advanced:

"InterfaceDesign"
http://www.artima.com/interfacedesign/contents.html

"Hacking Java"
http://www.wutka.com/hackingjava/

Cheers,

davidp /

- --
David Postill

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370

iQA/AwUBP8EbaXxp7q1nhFwUEQJDvgCgx0QEepVwrNRetKFoI9hMPXpM6FcAoMY6
rPINw191LPFFb3zkkmnILYRU
=fPR2
-----END PGP SIGNATURE-----







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.