一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jsp if else语句使用方法

时间:2022-06-29 02:39:25 编辑:袖梨 来源:一聚教程网

if else在大部份编程语言中都是这样使用的,我们今天来简单的介绍一下关于jsp教程 中的if else 与多重条件判断。


 
    Using the if Statement
 

 
   

Using the if Statement


    <%
        int value = 10;

        if(value > 0)
            out.println("Absolute value of " + value + " = " + value);
    %>
 

简单对比


 
    Using Compound Statements
 

 
   

Using Compound Statements


    <%
        int value = 10;

        if(value > 0) {
            out.println("The number was positive.");               
            out.println("Absolute value of " + value + " = " + value);
        }
    %>
 


if else


 
    Nested if Statements
 

 
   

Nested if Statements


    <%
        double value = 2;

        if (value != 0) {
            if (value > 0)
               out.println("The result = " + (1 / value));
            else
               out.println("Sorry, we need a positive number.");
        }
    %>
 

多个条件if else


 
    Using an if-else Ladder
 

 
   

Using an if-else Ladder


    <%
        String day = "Friday";

        if(day == "Monday")
            out.println("It's Monday.");
        else if (day == "Tuesday")
            out.println("It's Tuesday.");
        else if (day == "Wednesday")
            out.println("It's Wednesday.");
        else if (day == "Thurssday")
            out.println("It's Thursday.");
        else if (day == "Friday")
            out.println("It's Friday.");
        else if (day == "Saturday")
            out.println("It's www.111com.net/5230/ Saturday.");
        else if (day == "Sunday")
            out.println("It's Sunday.");
    %>
 

热门栏目