Java2024/src/chapter5/Example02.java
2024-11-06 13:16:26 +08:00

14 lines
637 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chapter5;
public class Example02 {
public static void main(String[] args) {
String s = "abcdabc";
System.out.println("字符串的长度为:" + s.length());
System.out.println("字符串中第一个字符:" + s.charAt(0));
System.out.println("字符c第一次出现的位置:" + s.indexOf('c'));
System.out.println("字符c最后一次出现的位置:" + s.lastIndexOf('c'));
System.out.println("子字符串ab第一次出现的位置" + s.indexOf("ab"));
System.out.println("子字符串ab字符串最后一次出现的位置" + s.lastIndexOf("ab"));
}
}