Indicate the outputs of the following code segments: a. String str = The rain in Spain falls
Fantastic news! We've Found the answer you've been seeking!
Question:
Indicate the outputs of the following code segments:
a. String str = "The rain in Spain falls mainly on the plain";
System.out.println(str.indexOf(' '));
b. String str = "The rain in Spain falls mainly on the plain";
System.out.println(str.indexOf(' ', 4));
c. String str = "The rain in Spain falls mainly on the plain";
System.out.println(str.substring(4));
d. String str = "The rain in Spain falls mainly on the plain";
System.out.println(str.substring(4, 8));
e. String str = "The rain in Spain falls mainly on the plain";
int begin = 0;
while (begin < str.length()){
int end = str.indexOf(' ', begin);
if (end == -1)
end = str.length();
String word = str.substring(begin, end);
System.out.println(word);
begin = end + 1;
}
Related Book For
Posted Date: