Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes printing on the same line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "printing on the same line" Watch "printing on the same line" New topic
Author

printing on the same line

John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
String hecules ="strong";

System.out.println(hercules.length);
System.out.print("5");
System.out.println();
}
}

I want the output to be displayed like 555555.
What am i doing wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

Well this has nothing at all to do with .length, so I've modified your subject.

If you don't want the line feeds, don't use println().


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Ok...bases on the hercules.length i want it to print 555555(derived from length).i am afraid you dont get it
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18523
    
  40

John Valiant wrote:Ok...bases on the hercules.length i want it to print 555555(derived from length).i am afraid you dont get it



The length is just a number (in this case, the value of 6), if you print it, you just get the number 6 printed. If you want to use the value to determine the number of times another number is printed -- well, one option would be to use a loop.

Henry
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Ok thanks will look up on loop.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: printing on the same line
 
Similar Threads
Array
Enhanced For Loop
Strange IF condition
Set all ComponentOrientation to rtl
auto boxing additions