Results 1 to 3 of 3
Thread: Print a blank space
- 07-25-2007, 07:56 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 44
- Rep Power
- 0
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:
notice there is such big gabs but not the last 2 lines....did i wroteJava Code:* ** *** **** *****
something wrong?
I would like to display the asteric sign "*"
to the right side instead left side like above.
This is my coding
ThanksJava 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("*"); } } } }
- 07-30-2007, 09:21 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
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
- 07-30-2007, 01:58 PM #3
Senior Member
- Join Date
- Jul 2007
- Posts
- 130
- Rep Power
- 0
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
Hope this helps :DJava 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("*"); } } }
Similar Threads
-
how can we remove blank lines from a .txt
By Camden in forum New To JavaReplies: 12Last Post: 07-29-2011, 01:38 PM -
java.lang.OutOfMemoryError: Java heap space
By paul in forum Advanced JavaReplies: 11Last Post: 06-12-2010, 05:30 PM -
Space Exploration dev 6
By JavaBean in forum Java SoftwareReplies: 0Last Post: 03-25-2008, 04:48 PM -
Waste Space & Text Field
By Gajesh Tripathi in forum AWT / SwingReplies: 2Last Post: 12-01-2007, 07:44 AM -
Blank result for jsp_servlet in Eclipse
By Unni in forum EclipseReplies: 2Last Post: 07-12-2007, 04:30 AM


LinkBack URL
About LinkBacks

Bookmarks