- length() 返回字符串中的字符数
- charAt(index) 返回字符串中指定位置的字符
- concat(s1) 将本字符串和字符串s1连接,返回一个新字符串
- toUpperCase() 返回一个新字符串,其中所有的字母大写
- toLowerCase() 返回一个新字符串,其中所有的字母小写
- trim() 返回一个新字符串,去掉两边的空白字符
package test2;
import java.util.Scanner;
public class String_object {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String str = input.nextLine();
System.out.println("length "+length_(str));
}
public static int length_(String str) {
//在此处补全
int count=0;
while(true){
try{
str.charAt(count++);
}catch(Exception e){
count--;
break;
}
}
return count;
}
}