Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Substring method

 
Shane Timlin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I came across the following question in my revision -


Given:



What will be printed by the above code if it is run with command line: java TestClass --0.50 (There are two minuses before 0.)

The explanation says
str.substring(1, str.length()-1) => "--0.50".substring(1, (6-1) ) => -0.5
which still seems too brief for me.
Could somebody explain how I tgets to -0.5?
I see this then gets rounded down to 0 and case 0 & case 1 are applied.

regards

SeanMor
 
Roel De Nijs
Sheriff
Posts: 10594
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources and use code-tags for better readibility of the code snippets.

Strings are 0-based and with substring the begin-index is included, the end-index is not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic