public class ZiFuChuan {
public static void main(String args[])
{
char a[] = { 'g','o','o','d'};
String s = new String(a);
System.out.println(s);
char b[] = {'n','o','b','s','t','u','d','e','n','t'};
String s1 = new String(b,3,7);//取一段字符
System.out.println(s1);
String s2 = "are students";
String s3 = new String("We");
String s4 = s3 + " " + s2;//字符串的拼接
System.out.println(s4);
int size = s2.length();//字符串的长度
System.out.println(size);
int place1 = s1.indexOf("t");//字符串t在字符串s1第一次出现的位置
int place2 = s1.lastIndexOf("t");//字符t在字符串s1最后一次出现的位置
System.out.println(place1);
System.out.println(place2);
int booktime = 4;
float pratice = 2.5f;
System.out.println("I use"+" "+booktime+" hours reading book; "+
(booktime+pratice)+ " play"+" "+"computer");
}
}
运行结果
good
student
We are students
12
1
6
I use 4 hours reading book; 6.5 play computer