学习编程第五章 Java篇
String类
声明字符串
在java语句中字符串必须包含在一对双引号(“ ”)之内。例如
“23.23”,“ABCDER”,“你好”
字符串是可以是任何信息 甚至单个字符
用一个字符串a创建String对象
char a[] = {'g','o','o','d'}
string s = new String(a);
等价于:
String s = new String(“good”)
连接字符串
连接多个字符串可以用 “+” 号来连接 “+” 号可以连接多个字符串并产生一个String对象
String s1 = new String("lello");
String s2 = new String("word");
String s = s1+""+s2;
System.out.println(s);
输出hello word
连接其他类型字符串
int book = 4;
float practice = 2.5f;
System.out.println("我每天花费"+book+“小时看书;”+practice+“小时上机练习”