运算符
- 算术运算符 + - * / % ++ - -
- 赋值运算符=
- 关系运算符> < >= <= == != instanceof
- 逻辑运算符&& || !
- 位运算符& | ^ ~ >> << >>>
- 条件运算符? :
- 扩展运算符+= - = *= /=
算术运算符
package operator;
import base.*;
public class Demo1 {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 30;
int d = 40;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);//类型转换
}
}
package operator;
public class Demo2 {
public static void main(String[] args) {
long a = 1212123123123L;
int b = 141;
short c = 16;
byte d = 8;
System.out.println(a+b+c+d);//Long
System.out.println(b+c+d);//int
System.out.println(c+d);//int
System.out.println(c+d);
}
}
关系运算符:返回结果为布尔值

本文详细介绍了Java中的运算符,包括算术、关系、逻辑、位及赋值运算符,还讨论了自增自减和三元运算符。此外,还讲解了JavaDoc的使用,如生成JDK帮助文档,以及包机制的作用,如防止命名冲突和如何使用package和import。
最低0.47元/天 解锁文章
1080

被折叠的 条评论
为什么被折叠?



