关系运算符用来比较两个值的关系,其运算结果是boolean型,当运算符对应的关系成立是,运算结果真为true,假为false。
假设变量a的值为10,变量b的值为5:
实例:
publicclassMain{publicstaticvoidmain(String[]args){inta=5;intb=10;System.out.println(a==b=+(a==b));System.out.println(a!=b=+(a!=b));System.out.println(a>b=+(a>b));System.out.println(a<b=+(a<b));System.out.println(a>=b=+(a>=b));System.out.println(a<=b=+(a<=b));}}
运行结果如下:
a==b=falsea!=b=truea>b=falsea<b=truea>=b=falsea<=b=true