Results 1 to 11 of 11
Thread: add a space after 10 lines?
- 01-20-2010, 08:38 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
add a space after 10 lines?
Hi I have a for loop, but I need to add a space after the first 10 positions. Anyone know how this can be done?
Thanks for your helpJava Code:public void one() { // put your code here System.out.println("Value Character"); for(int i = 32; i < 127; i++){ System.out.println( i ); } }
- 01-20-2010, 08:52 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
if statement should help here. Try it.
- 01-20-2010, 08:56 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
would I put it after the println or before?
- 01-20-2010, 09:12 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-20-2010, 09:12 AM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Try it all and see.
You don't lose a dollar every time you try something on your compiler, do you?
- 01-20-2010, 09:26 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
i've been trying. I new to java so dont know much, but it would make it easier if I knew where to put it because every little mistake makes it not compile.
I cant seem to get the if statement right. This is what I have so far. I dont know how to tell it to print that space after the 10th line. This is what my if statement looks like so far.
Can you please guide me in the right direction?
thank you
Java Code:public void one() { // put your code here System.out.println("Value Character"); for(int i = 32; i < 127; i++){ System.out.println( i ); if( i < 127 &&){ System.out.println(" "); } }
- 01-20-2010, 09:47 AM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Of course it doesn't compile like that. What is the && supposed to be doing in there?
Also you said print space after 10 positions. So the if should be trying to say if this is now the 10th position then print a space.
You have an index i which is incrementing. If you started at 32 then you whould work out what i will be after ten "positions". That's what you use to control your if.
- 01-20-2010, 11:29 AM #8
u can also implement a counter say c which will keep the track of ur line no.
lyk
System.out.println("Value Character");
int c=0;
for(int i = 32; i < 127; i++)
{
System.out.println( i );
c++;
if (c%10==0)
System.out.println();
}
- 01-20-2010, 12:01 PM #9
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Why introduce a new counter when there is already an index?
- 01-20-2010, 12:07 PM #10
using counter...i always find it easy..i mean to say if i m using the same index i thn dont u think the logic wd be complex
- 01-20-2010, 12:12 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you think that what happen in each time you declare a variable in your system?
Similar Threads
-
Help explain the FOR lines please
By hydride in forum New To JavaReplies: 2Last Post: 01-19-2010, 11:52 PM -
SWT Canvas drawing realtive to image space not canvas space.
By bobbie in forum SWT / JFaceReplies: 0Last Post: 07-05-2009, 12:31 PM -
Anyway to fix the lines so they dun shift?
By PeterFeng in forum New To JavaReplies: 0Last Post: 01-14-2009, 10:26 AM -
Random Lines
By Urgle in forum New To JavaReplies: 29Last Post: 11-12-2008, 03:42 PM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks