Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2007, 08:56 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
Print a blank space
Hi, i was trying out a simple program using loops displaying the "*" sign
line by line with space after each line.
however, i would like to try displaying the output in the other way instead
but not sure how ... Can anyone guide me and pin point it to me?
And i wonder why my blank space line some are so wide apart and some
are not??

My current output looks like this:
Code:
* ** *** **** *****
notice there is such big gabs but not the last 2 lines....did i wrote
something wrong?

I would like to display the asteric sign "*"
to the right side instead left side like above.

This is my coding

Code:
public class exercise2 { public static void main(String args[]) { int currwidth; for (int i=0; i<6; i++) { currwidth = 6 - i; for (int x=0; x<currwidth; x++) { System.out.println(" "); } for (int y=0; y<i; y++) { System.out.print("*"); } } } }
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 10:21 AM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
public class ex1
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(" *");
}
System.out.println("");
}

}}

I think it would give the result eaxctly wanted by you
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 02:58 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Hmm, why don't u try defining the borders for each side first before u make the code?
It'll be easier u know

Btw, the fault u got in ur code was the println(" "), thats why it creates a gap that eventually became smaller as ur code reach its end, try do a logic simulation of the code in ur notepad, ull see whats wrong, at 1st its gonna print about 10 or 11 lines first before putting a *, havent count it yet

Code:
public class exercise { public static void main(String[] args) { for (int i = 1; i <=6 ; i++) //i = coordinate x { space = 6-i; //the amount of space needed for (int j = 1; j <= space ; j++) // j = coordinate y { System.out.println(" "); } System.out.println("*"); } } }
Hope this helps
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Space Exploration dev 6 JavaBean Java Announcements 0 03-25-2008 05:48 PM
how can we remove blank lines from a .txt Camden New To Java 1 03-12-2008 07:02 AM
Waste Space & Text Field Gajesh Tripathi AWT / Swing 2 12-01-2007 08:44 AM
java.lang.OutOfMemoryError: Java heap space paul Advanced Java 1 07-25-2007 09:07 PM
Blank result for jsp_servlet in Eclipse Unni Eclipse 2 07-12-2007 05:30 AM


All times are GMT +3. The time now is 12:05 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org