zoukankan      html  css  js  c++  java
  • java-控制语句if/else

    Java if语句用于测试条件。它检查布尔条件为:true 或 false。

    语法格式:

    if(condition){
        //if语句块 => code to be executed.
    }
    //实例:
    public class IfExample{
      public static void main(String [] args){
        int age = 27;
        if (age>18){
          System.out.print("Age is greater than 18.");
        }
      }  
    if(condition){
        //code if condition is true   
    }else{
        //code if condition is false
    }

    //实例:
    public class IfElseExample{
      public static void main(String [] args){
        int number =13;
        if (number % 2 == 0){
          System.out.println("这是一个偶数。");
        }else{
          System.out.println("这是一个奇数。");
        }
      }
    }
    if (){
      //code to be executed if condition1 is true.
    }else if (){
      //code to be executed if condition2 is true.
    }else if (){
      //code to be executed if condition3 is true. }else{
      //code to be executed if all the conditions are false.
    }

    //实例:
    public class IfElseExample{
      public static void main(String [] args){
        int marks = 65;
        if (marks<50){
          System.out.println("fail");
        }else if (marks >= 50 && marks < 60){
          System.out.println("D grade");
        }else if (marks >= 60 && marks < 70){
          System.out.println("C grade");
        }else if (marks >= 70 && marks < 80){
          System.out.println("B grade");
        }else if (marks >= 80 && marks < 90){
          System.out.println("A grade");
        }else if (marks >= 90 && marks <100){
          System.out.println("A+ grade");
        }else{
          System.out.println("Invalid!");
        }
      }
    }
  • 相关阅读:
    Thread中带参方法无法使用之解决方案
    项目相关的风险要素及分类
    AspNetPager分页示例之DataGrid(PostBack分页)
    Substitution 类 (asp.net 2.0 )
    自定义HTTP处理程序显示图片(asp.net 2.0)
    常见文件扩展名和它们的说明
    基于.NET的开源GIS项目(转)
    项目开发流程标准
    AOP(Aspect Oriented Programming) 面向方面编程
    项目实施及管理标准
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/12852729.html
Copyright © 2011-2022 走看看