运算符
* 基本算数运算符:+ - * / %(余数)
* 赋值运算符:=(赋值) ==(恒等于) !=(不等于)
* += -= *= /= %=
* 逻辑运算符
* 条件运算符
*
*
*丢失精度 !非
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
int x = 100; //创建变量并赋值
int y = 67;
int sum; //创建变量
sum = x + y;
System.out.println(sum);
int c = x*y;
System.out.println(c);
int chu = x/y;
System.out.println(chu);
int qu = x%y;
System.out.println(qu);
boolean flags;
flags = (x==y);
System.out.println(flags);
System.out.println(x!=y);
}
}
比较运算符
* (恒等) != >= <= > <
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
int x = 90, y = 70;
boolean flags;
flags = (xy);
System.out.println(flags);
flags = (x!=y);
System.out.println(flags);
flags = (x>=y);
System.out.println(flags);
flags = (x<=y);
System.out.println(flags);
flags = (x>y);
System.out.println(flags);
flags = (x<y);
System.out.println(flags);
}
}
赋值运算符:=(赋值) ==(恒等于) !=(不等于)
* += -= *= /= %=
* 逻辑运算符
* 条件运算符
*
*
*丢失精度 !非
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
int a = 10;
int b = 260;
b += a;
System.out.println(a);
System.out.println(b);
b -=a;
System.out.println(b);
b *=a;
System.out.println(b);
b /=a;
System.out.println(b);
b %=a;
System.out.println(b);
}
}
逻辑运算符
* &&(短路与)and 只有两个值都为真才为真,否则都为假
* ||(短路或)or 只要有一个真都为真
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
boolean x = true, y = false;
System.out.println(x && x);
System.out.println(x && y);
System.out.println(y && x);
System.out.println(y && y);
System.out.println(x || x);
System.out.println(x || y);
System.out.println(y || x);
System.out.println(y || y);
}
}