This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 5139
    
  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
 
Similar Threads
How to validate Text field in java.It should accept only numric value.
how to find all possible combinations of charcters in string
output is not coming please help
Get middle initial
Enthuware alpha SCJP 5 mock exam