运算符 operator
算数运算符:+,-,*,/,%
赋值运算:=
关系运算符:>, <, >=, <=, ==, !=
逻辑运算符:&& (与), || (或),!(非)
Intellil IDEA 新建一个包—右击src—NEW—package(包);
//然后把需要的内容加入包内,方便管理
package operator;//包 名称operator
public class ys { //类名
public static void main(String[] args) { //min 方法
int a=10;
int b=11;
int c=2;
int d=5;
System.out.println(a+b);//21
System.out.println(c*b);//22
System.out.println(d/(float)c);//2.5 是小数所以需要强制转换类型 int整数转浮点数
}
}
如果多个操作数的数据类型不同,那么输出结果一定是高类型
package operator;
public class gd {
public static void main(String[] args) {
long a = 34566.67;
int b =678;
short c= 8;
byte d=6;
System.out.println((int) (a+b+c+d));//多个操作数中有一个为long,那么输出也为long
System.out.println(b+c+d);//多个操作数中没有long,那么输出为int
System.out.println(c+(double)d);//低类型转高类型 自动转换 结果一定是double类型
}
}
关系运算符返回结果:正确 true 错误 false
package operator;
public class bj {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 21;
System.out.println(a>b);//false
System.out.println(a<b);//true
System.out.println(c%a);// 21/10 余数为1 摸运算,取余数
}
}