Groovy在线运行

版本:

所属目录
点击了解高性能代码运行API
运行结果
教程手册
代码仓库
极速运行
终端运行
图形+终端

                        
用户最新保存的代码
查看更多
显示目录

嵌入If语句



搭载国产梦丘操作系统,支持安装软件,在线编程可视化开发软件,无需配置开发环境

点击购买 梦丘固件

嵌入If语句

有时需要有多个if语句嵌入在彼此内部。

这种说法的一般形式是-

if(condition) { 
   statement #1 
   statement #2 
   ... 
} else if(condition) { 
   statement #3 
   statement #4 
} else { 
   statement #5 
   statement #6 
}

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

class Example { 
   static void main(String[] args) { 
      // Initializing a local variable 
      int a = 12 

      //Check for the boolean condition 
      if (a>100) {
         //If the condition is true print the following statement 
         println("The value is less than 100"); 
      } else 
         // Check if the value of a is greater than 5 

      if (a>5) { 
         //If the condition is true print the following statement 
         println("The value is greater than 5 and greater than 100"); 
      } else { 
         //If the condition is false print the following statement 
         println("The value of a is less than 5"); 
      }  
   } 
}

在上面的示例中,我们首先将一个变量初始化为值12。在第一个if语句中,我们看到a的值是否大于100。如果没有,那么我们进入第二个循环,看看a的值是否大于5或小于5。上面的代码的输出将是-

The value is greater than 5 and greater than 100
由JSRUN为你提供的Groovy在线运行、在线编译工具
        JSRUN提供的Groovy 在线运行,Groovy 在线运行工具,基于linux操作系统环境提供线上编译和线上运行,具有运行快速,运行结果与常用开发、生产环境保持一致的特点。