与Java的初遇——String与8种基本数据类型间的运算

String与8种基本数据类型间的运算

  • String属于引用数据类型

  • 声明String类型变量时使用一对

  • String可以和8种基本数据类型变量做运算,且运算只能是连接运算:+

  • 运算的结果仍然是String类型

//例 public class StringTest{     public static void main(String[] args){         String s1 = Hello World!;         System.out.println(s1);         char c = 'a';         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((c + num) + str);         System.out.println(str + num + c);     } } /* 输出结果为: Hello World! 107hello ahello10 a10hello 107hello hello10a */