day02-数据类型转换_强制转换-小数的转换
This commit is contained in:
19
day02/src/com/inmind/datatype/Demo04.java
Normal file
19
day02/src/com/inmind/datatype/Demo04.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.inmind.datatype;
|
||||
/**
|
||||
小数强转为整数,如何操作的??强制类型转换
|
||||
小数转为整数的结果:直接将小数的小数位去掉(精度丢失)
|
||||
*/
|
||||
public class Demo04 {
|
||||
public static void main(String[] args) {
|
||||
//定义一个单精度浮点数变量
|
||||
float f = 3.14F;
|
||||
//能不能转为整数??
|
||||
int i = (int) f;
|
||||
System.out.println(i);//3
|
||||
//定义一个单精度浮点数变量
|
||||
double d = 3.1425926;
|
||||
//能不能转为字节??
|
||||
byte b = (byte) d;
|
||||
System.out.println(b);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user