Bookmark Topic Watch Topic
  • New Topic

Error Returning in my toString  RSS feed

 
Sammie Hassett
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Report post to moderator
To string Returns the last character doubled
How do i stop it from doubling the last number?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Report post to moderator
How are you trying to print them? Can you please show us?
 
Sammie Hassett
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Report post to moderator
Tushar Goel wrote:How are you trying to print them? Can you please show us?


Sure I have a test code:
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is what i thought so.. It is printing 2 things: 1) println in the constructor and 2) toString()

in println you are printing whole string and in toString() last char is printing. So that's why you got 2 char in last.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Cross posted in http://www.coderanch.com/t/649175/java/java/string-printing-digits
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
And so I'm closing this thread, as discussion is proceeding nicely in the other one.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!