下面简单介绍运算符的分类;
算术运算符
package com.example.运算符; public class demo1 { public static void main(String[] args) { System.out.println(5/2);//返回整数 除 2 System.out.println(5%2);//返回整数 余数 1 //i++ ++i int i=10; ++i; System.out.println(i); i++; System.out.println(i); //++f 先自增,后运算 int f=10; System.out.println(++f +10); System.out.println(f); //d++ 先运算,后自增 int d =10; System.out.println(d++ +10); System.out.println(d); } }
运行结果:
2 1 11 12 21 11 20 11 Process finished with exit code 0
关系运算符
public static void main(String[] args) { int score =70; System.out.println(score >=60); System.out.println(score ==100); System.out.println(score !=60); }
结果如下:
true false true
逻辑运算符
&& 两者必须同事满足 与 才为true
|| 两者满足一个即可 或 即可为true
赋值运算
public static void main(String[] args) { int abc=1000; int b = 0; int b1 = 0; //代码前后代码 b=b+abc; // b=b+1000 b1+=abc; // b1+=1000; System.out.println(b); System.out.println(b1); System.out.println(b==b1); }
运行结果如下:
1000 1000 true