diff --git a/day02/src/com/inmind/datatype/Demo04.java b/day02/src/com/inmind/datatype/Demo04.java new file mode 100644 index 0000000..b666f39 --- /dev/null +++ b/day02/src/com/inmind/datatype/Demo04.java @@ -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); + } +}