003-JavaString数据类型

String类型可以和8中基本数据类型做运算(byte/short/char/int/long/float/double/boolean),且只能是连接运算

1. 区分 连接符 和 “+” 的区别

char c = 'a';
int num = 10;
String str = "hello";
System.out.println(c + str + num); //ahello10
System.out.println(str + (c + num));//hello107
System.out.println(c + num + str);//107hello

2.输出 “*  *”这样的一个字符串,其中字符串中间的空白是制表符

System.out.println("*   *");//成功
System.out.println('*' + '	' + '*');//93
System.out.println('*' + '	' + "*");//51*,右上一行和本行,可得到*的ascii码值为42
System.out.println('*' + "	" + '*');//成功
System.out.println("*" + '	' + '*');//成功
System.out.println('*' + ('	' + "*"));//成功
原文地址:https://www.cnblogs.com/Sinkinghost/p/10987607.html