day02-运算符_算术运算符
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.inmind.datatype;
|
||||
package com.inmind.datatype01;
|
||||
/*
|
||||
数据类型转换---自动转换
|
||||
Java程序中要求参与的计算的数据,必须要保证数据类型的一致性,如果数据类型不一致将发生类型的转换。
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.inmind.datatype;
|
||||
package com.inmind.datatype01;
|
||||
/*
|
||||
注意:范围小的类型向范围大的类型提升,byte、short、char 运算时直接提升为int
|
||||
byte、short、char-->int-->long-->float-->double
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.inmind.datatype;
|
||||
package com.inmind.datatype01;
|
||||
/**
|
||||
强制转换:大范围的数据类型转换为小范围的数据类型
|
||||
语法格式:
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.inmind.datatype;
|
||||
package com.inmind.datatype01;
|
||||
/**
|
||||
小数强转为整数,如何操作的??强制类型转换
|
||||
小数转为整数的结果:直接将小数的小数位去掉(精度丢失)
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.inmind.datatype;
|
||||
package com.inmind.datatype01;
|
||||
|
||||
/**
|
||||
字符在数学运算中的体现,是遵循ASCII码表,将码表中对应的十进制的值参与运算
|
||||
|
||||
29
day02/src/com/inmind/yunsuan02/Demo06.java
Normal file
29
day02/src/com/inmind/yunsuan02/Demo06.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.inmind.yunsuan02;
|
||||
/**
|
||||
算数运算符:+ - * / % ,++ --
|
||||
|
||||
注意:
|
||||
1.算数运算时,运算符前后的数据类型如果一致,那么结果也是该类型
|
||||
2.算数运算时,运算符前后的数据类型如果不一致,那么结果是大范围的数据类型
|
||||
|
||||
有特例:byte,short,char,这3个类型在运算时,都会提升为int
|
||||
*/
|
||||
public class Demo06 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(1+3);//4
|
||||
System.out.println(1-3);//-2
|
||||
System.out.println(1*3);//3
|
||||
System.out.println(10/3);//3
|
||||
System.out.println(10%3);//1
|
||||
System.out.println("--------------");
|
||||
System.out.println(3124/1000*1000);//3000
|
||||
System.out.println(3124/1000.0*1000);//3124.0
|
||||
|
||||
System.out.println("----------以下是特殊情况------------");
|
||||
byte b1 = 3;
|
||||
byte b2 = 5;
|
||||
int sum = b1+b2;//byte,short,char,这3个类型在运算时,都会提升为int
|
||||
byte sum1 = (byte)(b1+b2);
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user