day02--数据类型转换_自动转换的举例和顺序
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.inmind;
|
||||
/*
|
||||
自动转换:将取值范围小的类型自动提升为取值范围大的类型 。
|
||||
数据类型转换---自动转换中转换顺序
|
||||
|
||||
转换顺序:byte、short、char---->int---->long---->float---->double
|
||||
|
||||
强调:byte、short、char 在运算都是直接提升至int
|
||||
*/
|
||||
public class Demo02 {
|
||||
public static void main(String[] args) {
|
||||
byte b1 = 127;
|
||||
short s = b1;
|
||||
int i = b1+s;
|
||||
long l = i + s;
|
||||
float f = l+i;
|
||||
double d = f+l;
|
||||
System.out.println("---------------------------------");
|
||||
byte t1 = 10;
|
||||
byte t2 = 20;
|
||||
//short s1 = t1+t2;//注意:byte、short、char 在运算都是直接提升至int
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user