GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Jan-2009, 05:24
poleen poleen is offline
New Member
 
Join Date: Mar 2008
Posts: 16
poleen has a little shameless behaviour in the past
Unhappy

Diamond shaped asterisk in JAVA


im having hard time studying looping statement in java and also in some different programming language, thats why i am needing some help here creating a program which is a diamond shaped asterisk the output should be like this:

1 *
2 * * *
3 * * * * *
4 * * *
5 *

and also there is a participation of the user that the user must input an odd number, the odd number represents the level of the diamonds example 5, the output should be like the above output...
hirs my code... i know i have a lot of mistake with my looping statement in this program... tnx in advance...

JAVA Code:
class Asterisk

{public statis void main(String[] args)

{int x;
system.out.println("*")
for(x=1;x<=3;x++)
{system.out.println("*")}
for(x=1;x<=5;x++)
system.out.println("*")
for(x=1;x<=3;x++)
system.out.println("*")

}}


the output became:
*
*
*
*
*
*
*
*
*
*
*
*
*

really need your help... T.T
Last edited by LuciWiz : 06-Jan-2009 at 07:47. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 06-Jan-2009, 08:52
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 156
dlp has a spectacular aura about

Re: Diamond shaped asterisk in JAVA


system.out.println will always shift the next output to the next line on the console. system.out.print() will not make the next output appear on the next line. What you need to do is:
JAVA Code:
for(...)
  system.out.print("*");
system.out.println();
for(...)
  #3  
Old 07-Jan-2009, 01:15
poleen poleen is offline
New Member
 
Join Date: Mar 2008
Posts: 16
poleen has a little shameless behaviour in the past

Re: Diamond shaped asterisk in JAVA


nothing happens the output became like this:
*
*

*
*
*

*
*
*
*
*

*
*
*
*




but anyways tnx for your help..
  #4  
Old 07-Jan-2009, 09:35
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 156
dlp has a spectacular aura about

Re: Diamond shaped asterisk in JAVA


Really? This is my ouptut:

Code:
C:\Codes\Java\abdf>javac Asterisk.java C:\Codes\Java\abdf>java Asterisk * *** ***** *** *
Using the code change I suggested. Make sure your System.out.println(); line is not in the for loops so it's not repeated each time the loop iterates.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scalability in Java and C++ agx Miscellaneous Programming Forum 7 04-Feb-2006 15:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:28.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.