运算符
- java支持的运算符:
-
算术运算符: +,-,*,/,%,++,–
-
赋值运算符: =
-
关系运算符:>,<,>=,<=,!=, ==
-
逻辑运算符:&&,||,!
-
位运算符:&,|,^,~,>>,<<,>>>
-
public class Demo{
public static void main(String[] args){
int i = 0;
int j = 5;
System.out.println(i+j);
}
}
- 备注:java中的数学类:Math,里面包含了各种数学中用到的常用函数方法。
三元运算符
- ?:
- 例如
public class Demo{
public static void main(String[] args){
// x ? y : z
// 如果x为true ,返回y ,否则返回z
int score = 80;
String result = score>60?"成绩及格":"成绩不及格"
System.out.println(result)
}
}