This question is a very basic one.. but the answer given int the Sun Guoqiao's mock exam got me confused
What is the output of trying to compile and run the following code?
(Select one correct answer)
-----------------------------------------------------------------------
public class Test023
{
public static void main(
String args[])
{
String str = new String("Hello");
System.out.print(str.substring(0,3));
System.out.print(" ");
System.out.println(str.replace('r', 'h'));
}
}
-----------------------------------------------------------------------
A: Hell Hello
B: Hel Hel
C: Hel Hello
D: Hell Hell
My answer was A but the correct answer is C..
The API
doc has the following example which made me believe that the string index starts from 0 & not 1.
"smiles".substring(1, 5) returns "mile"
Can anybody clear my confusion