|
|
|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

10-06-2008, 03:49 PM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 4
|
|
|
Star pattern help?
I need some help making some star patterns. The exact instructions are as follows:
Create separate programs to produce the following patterns:
a.
*
**
***
****
*****
b.
*****
****
***
**
*
I have to use for loops to get the patterns and I've already got (a.) but I can't seem to get the second. My first pattern's code is this:
public class Stars
{
//-------------------------------------------
//Prints a triangle shape using asterick (star) characters.
//-----------------------------------------------------------
public static void main (String[] args)
{
final int MAX_ROWS = 10;
for (int row = 1; row <= MAX_ROWS; row++)
{
for (int star = 1; star <= row; star++)
System.out.print ("*");
System.out.println();
}
}
}
Please help? Thanks in advance!
|
|

10-06-2008, 03:54 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
|
|
Simply do the process in other way around.
public class Stars {
//-------------------------------------------
//Prints a triangle shape using asterick (star) characters.
//-----------------------------------------------------------
public static void main (String[] args) {
final int MAX_ROWS = 10;
for (int row = MAX_ROWS; row >= 0; row--) {
for (int star = 1; star <= row; star++) {
System.out.print ("*");
}
System.out.println();
}
}
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

10-06-2008, 03:58 PM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 4
|
|
|
Oh, wow. Thank you so much! I really appreciate it.
|
|

10-06-2008, 04:02 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
|
|
|
You are welcome!
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

11-19-2008, 05:35 AM
|
|
Member
|
|
Join Date: Nov 2008
Posts: 12
|
|
|
star
can i hav the explanation for the code u hv sent a while ago about creating a star?? coz i am little bit confuse?
Last edited by jhen : 11-19-2008 at 05:37 AM.
|
|

11-19-2008, 05:38 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
|
|
|
On what you are confusing, not what line of code?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

11-19-2008, 10:17 AM
|
|
Member
|
|
Join Date: Nov 2008
Posts: 12
|
|
|
star
wt is the used of final in the source code of creating a star??? y is it the identifier named row and star doesn't hav error eventhough it was not declared???
plz i nid uir help... tnx
|
|

11-19-2008, 10:20 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
|
|
|
In Java final means constant. Basically the value cannot change at run time. Always it remain as the same. Just remove the word final and run the code. Still you get the same result. It's just for safety, in this case it's not much important but it's good practice.
Carefully check the code, both start and row identifiers are declared in the code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

11-19-2008, 10:36 AM
|
|
Member
|
|
Join Date: Nov 2008
Posts: 12
|
|
|
TY
tnx .... it's a help for me to be one of the member of this forum....sayoonara....
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
All times are GMT +3. The time now is 10:30 AM.
|
|
VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org