代碼
提交代碼
public class StringMethod1 {
public static void main(String[] args) {
// 創建String對象str
String str = "hello world!";
// 調用對象下length()方法,并使用int類型變量接收返回結果
int length = str.length();
System.out.println("str的長度為:" + length);
}
}
運行結果