Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing on the same line

 
John Valiant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
John Valiant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks will look up on loop.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic