java的算术运算符
This commit is contained in:
33
day02/src/com/inmind/Demo05.java
Normal file
33
day02/src/com/inmind/Demo05.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package com.inmind;
|
||||||
|
/*
|
||||||
|
算数运算符包括:
|
||||||
|
+ 加法运算,字符串连接运算
|
||||||
|
- 减法运算
|
||||||
|
* 乘法运算
|
||||||
|
/ 除法运算
|
||||||
|
% 取模运算,两个数字相除取余数
|
||||||
|
++ 、 -- 自增自减运算
|
||||||
|
|
||||||
|
总结:
|
||||||
|
1.算术运算时运算符前后的数据类型如果是一致,那么结果也就是该数据类型
|
||||||
|
2.算术运算时运算符前后的数据类型如果是不一致,那么结果也就是该数据类型中大范围的数据类型
|
||||||
|
|
||||||
|
|
||||||
|
有特例:byte,short,char,这3个类型在运算时,最终的结果都是int
|
||||||
|
*/
|
||||||
|
public class Demo05 {
|
||||||
|
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 int
|
||||||
|
System.out.println(10%3);//1
|
||||||
|
System.out.println("-----------------------");
|
||||||
|
System.out.println(3124/1000*1000);//3000 0
|
||||||
|
System.out.println(3124/1000.0*1000);//3124 3124 3124.0
|
||||||
|
System.out.println("------------------------");
|
||||||
|
/*byte b = 10;
|
||||||
|
byte b1 = 20;
|
||||||
|
byte sum = b+b1;*/
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user