- 布尔数据
描述的是一种逻辑处理结果,用boolean来进行布尔类型的定义,
注意:取值范围:true、false
例:
boolean flag = true;
if(flag){//判断flag的内容,如果是true就执行
System.out.print("hello");
有一些编程语言没有提供布尔类型,所以会使用0表示false,非0表示true,而这种逻辑在就Java中不存在。
2. String类型
在任何语言中都没有提供字符串,但实际在使用上来讲各个编程语言为了方便程序开发,都会提供有字符串的相应描述,在Java中使用的是String来定义,
由于String特殊,所以可以像普通变量那样采用直接赋值的方式进行字符串的定义,并且用“ " " ”进行字符串的表示。
String str = "hello world";
System.out.print(str);
可以使用 ‘+’ 来进行字符串的连接处理。
列:
String str = "hello";
str = str + "world"; //字符串连接
str += "!!!" //字符串连接
System.out.print(str);
注意:
“ + ” 的描述:
例:
double x= 10.1;
int y= 20;
String str = "计算结果" + x + y;
System.out.print(str);
结果:10.120
注意:数据范围大的与数据类型小的进行计算的时候,所有小的数据类型自动转换为数据范围大的,但是有String,所有的数据类型无条件变为String,如果有 ” + “ 便是的是字符串连接
double x= 10.1;
int y= 20;
String str = "计算结果" + (x + y);
System.out.print(str);
结果:30.1
描述字符串可以数用转义字符进行一些处理,例如:TAB(\t)、"(")、’(’)、换行(\n)、(\)。
例:
System.out.print("hello world !! \n hello" );
结果:
hello world !!
hello
System.out.print("hello world !! \n hello \"world\"!" );
结果:
hello world !!
hello “world”!