目录

if 声明

第一个决策声明是if语句。 本声明的一般形式是 -

if(condition) { 
   statement #1 
   statement #2 
   ... 
}

该陈述的一般工作是首先在if语句中评估条件。 如果条件为真,则执行语句。 下图显示了if语句的流程。

如果声明

以下是if/else语句的示例 -

class Example { 
   static void main(String[] args) { 
      // Initializing a local variable 
      int a = 2 
      //Check for the boolean condition 
      if (a<100) { 
         //If the condition is true print the following statement 
         println("The value is less than 100"); 
      } 
   } 
}

在上面的例子中,我们首先将变量初始化为值2.然后我们评估变量的值,然后决定是否应该执行println语句。 上述代码的输出将是 -

The value is less than 100
↑回到顶部↑
WIKI教程 @2018