java支持如下运算符:
- 算术运算符:+, – , *, / ,%,++,–
- 赋值运算符: =
- 关系运算符:>,< ,>=,<=,==,!=instanceof
- 逻辑运算符:&&,||,!(与,或,非)
- 位运算符:&,|,^,~,>>,<<,>>>(了解!!!)
- 条件运算符:?:
- 扩展运算符:+=,-=,*=,/=
package demo;
import jdk.swing.interop.SwingInterOpUtils;
public class demo3 {
public static void main(String[] args) {
//二元运算符
int a = 10;
int b = 20;
int c = 25;
int d = 25;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b); //在输出小数的时候,要强制转换
System.out.println(c/d);
System.out.println("====================================");
long q = 123123123123L;
int w = 123;
Short e = 10;
Byte r = 8;
System.out.println(q+w+e+r); //long
System.out.println(w+e+r); //int
System.out.println(e+r); //int
System.out.println("=====================================");
//++ -- 自增 自减 一元运算符
int f = 3;
int g = f++; //执行完这行运行代码前,先给f赋值,在自增
//f = f+1;
System.out.println(f);
//f++ f=f+1;
int h =++a; //执行完这行运行代码前,先自增,在给g赋值
System.out.println(g);
System.out.println(h);
}
}
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/244757.html