
-----------------------------------
hamid14
Thu Nov 18, 2010 6:22 pm

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?

-----------------------------------
TerranceN
Thu Nov 18, 2010 6:33 pm

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
Thu Nov 18, 2010 7:47 pm

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
Thu Nov 18, 2010 7:51 pm

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");
[/code]

-----------------------------------
TerranceN
Thu Nov 18, 2010 7:53 pm

RE:display text on the same line in a loop
-----------------------------------
You can use System.out.print() instead of System.out.println().

-----------------------------------
hamid14
Thu Nov 18, 2010 8:17 pm

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
Sat Nov 20, 2010 9:42 pm

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.
