首页 > 代码库 > Java 语法 索引 ----- 条件语句(If Else,Switch)

Java 语法 索引 ----- 条件语句(If Else,Switch)

if (x < 1)   System.out.print(x + " < 1");else if (x > 1)   System.out.print(x + " > 1");else    System.out.print(x + " == 1");

 

Switch

switch (y){  case 0: System.out.print(y + " is 0"); break;  case 1: System.out.print(y + " is 1"); break;  default:System.out.print(y + " is something else");}

 

三元运算符

x = (x < 0.5) ? 0 : 1;

 

If x < 0.5

   x = 0;

else

   x = 1 ;