立即学习:https://edu.csdn.net/course/play/27274/361059?utm_source=blogtoedu
1.算术运算
除数不能为0
//算术运算+-*/%
static void testMath(){
int a=(int)(Math.random()*100);
int b=(int)(Math.randow()*100);
system.out.println("a="+a);
System.out.printin("b="+b);
int result;
result =a+b;
System.out.print1n("a+b="+ result);
result=a-b;
system.out.printin("a-b="+result);
result=a*b;
System.out.println("a*b="+ result);
result=a/b;//结果取整
System.out.printin("a/b= "+ result);
result=a%b;
system.out.println("a%b="+ result);
//分母不能为0
int x=o,y=28;
//int r=y/x;
//system.cut.print1n(r);
//结果是浮点数
int i=10,j=3;
System.out.println(i/(float)j);
//字符串加运算
String nane ="Lom";
string email="tom@email.com";
int age=20;
string msg =name+","+email +","+ age;
system.out.println(msg);
}
}
2.关系运算
><
>=、<=、==、!=
3.逻辑运算
&、 |、!(取反)、&&(如果前面的表达式成立则后面的表达式不执行)、||
4.赋值运算
- 简单赋值
- 算术运算
- 自增(++)和自减(--)
5.条件运算(三元运算)
max=a>b?(c>a?c:a) :(c>b?c:b);