|
A.
String s = "perserverance";
String t = s.substring(4, 6);
String u = s.substring(3, 8);
String v = s.substring(0, 9);
System.out.println(t);
System.out.println(u);
System.out.println(v);
This is my explaination for the above code segment:
1. Takes the substream at the 5th character and stops at the 7th character in the string s.
2. Takes the substream at the 4th character and stops at 9th in the string s.
3. Takes the substream at the 1st character and stops at the 10th in the string s.
Is that correct? Is there any step after that? What is the output of it will look like?
|
|
|
class StringTest
{
public static void main(String[] args)
{
String s = "perserverance";
String t = s.substring(4, 6);
String u = s.substring(3, 8);
String v = s.substring(0, 9);
System.out.println(t);
System.out.println(u);
System.out.println(v);
}
} Is that correct?
substream should be substring. otherwise, yes
What is the output of it will look like?
C:\jexp>java StringTest
er
serve
perserver
<Added>
To avoid confusion, this:
Is that correct?
substream should be substring. otherwise, yes
might be more clear if written as:
Is that correct?
1. Takes the substream at the 5th character and stops at the 7th character in the string s.
"substream" in the statement above should be "substring". otherwise, yes
|
|
|
how would one describe this code segment
String s = "abracadabra";
int n1 = s.indexOf("ra");
int n1 = s.indexOf("ra", 2);
int n1 = s.indexOf("ra", 5);
int n1 = s.indexOf("ra", 10);
System.out.println(n1);
System.out.println(n2);
System.out.println(n3);
System.out.println(n4);
|
|
|
|
|
|
|
// |