布尔、String类型

  1. 布尔数据
    描述的是一种逻辑处理结果,用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”!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值