String s = new String("Hello World!");
// String s = "Hello World!"; 两种方式
System.out.println("s的长度为:"+s.length());
System.out.println("s的第二个字符为:"+s.charAt(2));//输出的为l,参数是从0开始的
System.out.println("s小写转大写:"+s.toUpperCase());
s = s+" How are you?";
System.out.println("连接后字符:"+s);
希望采纳!
public class TestString {
//主方法
public static void main(String[] args) {
//String s = "Hello World!";
String s = new String("Hello World!");//String类对象s
System.out.println("s的长度为:"+s.length());
System.out.println("第二个字符为:"+s.substring(1, 2));
//System.out.println("第二个字符为:"+s.charAt(1));//第二种方法
System.out.println("转化为大写"+s.toUpperCase());
System.out.println(s.concat(" How are you?"));//本题应该是考察这个函数
//System.out.println(s+" How are you?"));//第二种方法
}
}