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 ;

posted @ 2014-08-09 02:15  星月石  阅读(188)  评论(0编辑  收藏  举报