我是编程和处理Java String分配的新手.问题是:
这是我做的:
String phrase = new String ("This is a String test.");
String middle3 = new String ("tri"); //I want to print the middle 3 characters in "phrase" which I think is "tri".
middle3 = phrase.substring (9, 11); // this only prints out 1 letter instead of 3
System.out.println ("middle3: " + middle3);
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
Original phrase: This is a String test.
Length of the phrase: 18 characters
middle3: S
Run Code Online (Sandbox Code Playgroud)
我还认为字符串"短语"中有18个字符,但如果没有,请告诉我.提前感谢您的帮助!