String(字符串):引用数据类型
声明String使用一对双引号
string可以与8中数据类型做运算;且运算只能连接运算运算符+
运算结果也是string类型 ;a = 97
简单示例
class VariableTest1 { public static void main(String[] args) { String s1 = "chlgg"; System.out.println("Hello world"); System.out.println(s1); } } ---------- java ---------- Hello world chlgg 输出完成 (耗时 0 秒) - 正常终止
字符串拼接
class VariableTest1 { public static void main(String[] args) { String s1 = "chlgg"; System.out.println("Hello world"); System.out.println(s1); int number = 1001; String numberStr = "学号"; String info = numberStr + number; System.out.println(info); } }
测试
class VariableTest1 { public static void main(String[] args) { char c = 'a';//a等于97 int num = 10; String str = "hello"; System.out.println (c + num +str); System.out.println(c + str + num); System.out.println(c+ (num + str)); System.out.println((str + num +c)); } } ---------- java ---------- 107hello ahello10 a10hello hello10a 输出完成 (耗时 0 秒) - 正常终止