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