基本数据类型的强制转换

输出hello word
byte(-128~127)、short、char、int(最多十位数且以2开头)、long、float、double(精度比float高)、boolean
强制类型转换,大的转小的不需要变,小的转大的需要强制类型转换,在转换的值得前面加基本数据类型

  输出hello word
  byte(-128~127)、short、char、int(最多十位数且以2开头)、long、float、double(精度比float高)、boolean
  强制类型转换,大的转小的不需要变,小的转大的需要强制类型转换,在转换的值得前面加基本数据类型


public static void main(String[] args) {
	//hello word
	System.out.println("hello word !!!");
	
	//强制类型转换
	byte a=7;
	byte b=9;
	byte c=(byte)(a+b);
	System.out.println("byte="+c);
	
	System.out.println("----------");
	short f=5;
	short e=(short) (f+1);
	System.out.println("short="+e);
	System.out.println("----------------");
	char g = 6;
	char h = 8;
	char i = '9';
	System.out.println("char="+i);
	System.out.println("----------");
	//这个long类型比int大,所以不用类型转换
	long j = 2l;
	long k = 3l;
	long l = j+k;
	System.out.println("long="+l);
	System.out.println("---------");
	float m = 3.5f;
	float n = 4.0f;
	float o = m+n;
	System.out.println("float="+o);
	System.out.println("---------");
	double p = 7.8;
	double q = 8.9;
	double r = p+q;
	System.out.println("double="+r);
	System.out.println("----------");
	boolean s = false;
	boolean t = true;
	System.out.print(s+" "+t);
}

输出结果
hello word !!!
byte=16

short=6

char=9

long=5

float=7.5

double=16.7

false true

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值