wood burning stoves 2.0*
The moose likes Associate Certification (OCAJP 7) and the fly likes Substring method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "Substring method" Watch "Substring method" New topic
Author

Substring method

Shane Timlin
Greenhorn

Joined: Aug 15, 2013
Posts: 1
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
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Substring method