Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 display text on the same line in a loop
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hamid14




PostPosted: Thu Nov 18, 2010 6:22 pm   Post subject: display text on the same line in a loop

Im trying to display the int variable called number in a straight line while it is increasing. how would i do this, without going to the next line, until something else is true?
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Thu Nov 18, 2010 6:33 pm   Post subject: RE:display text on the same line in a loop

What do you mean display a number in a straight line?

Also what output method are you using? System.out, hsa.Console or something else?
hamid14




PostPosted: Thu Nov 18, 2010 7:47 pm   Post subject: Re: display text on the same line in a loop

im using system.out, i wanna put the new next number beside the old number on the same line
TheGuardian001




PostPosted: Thu Nov 18, 2010 7:51 pm   Post subject: Re: display text on the same line in a loop

I'm going to assume you're using Java, because nobody should use RTP over that.

As long as you never print a newline character, your input will continue on the same line. System.out.print() will print text without automatically appending a newline character on the end (as opposed to the println method, which does append the newline character.) When you want to go to a new line, just print a newline (\n) character.

code:

System.out.print("This");
System.out.print("is");
System.out.print("all");
System.out.print("on");
System.out.print("one");
System.out.print("line");
TerranceN




PostPosted: Thu Nov 18, 2010 7:53 pm   Post subject: RE:display text on the same line in a loop

You can use System.out.print() instead of System.out.println().
hamid14




PostPosted: Thu Nov 18, 2010 8:17 pm   Post subject: Re: display text on the same line in a loop

Okay, thanks guys. I was using this before, but netbeans was had errors and it showed a red line under it saying value is not initalized. lol just needed to restart netbeans lol.
SS1389




PostPosted: Sat Nov 20, 2010 9:42 pm   Post subject: Re: display text on the same line in a loop

System.out.print() does the job quite nicely.

If you were to type:

System.out.print("This ");
System.out.println("is a test.");

The output would be This is a test.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: