1.比较两个整数是否相等:spa
class Hello2 { public static void main(String[] args) { int x = 10; int y = 5; boolean b = (x == y) ? true : false; System.out.println("b = " + b); } }
结果:3d
true : false能够省略,由于(x = y)这个判断的结果不是true就是false.code
2.取三个数中的最大值:blog
class Hello2 { public static void main(String[] args) { int a = 10; int b = 20; int c = 30; int temp = (a > b) ? a : b; int max = (temp > c) ? temp : c; System.out.println("max = " + max); } }
结果:class