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!");
        }
      }
    }
  • 相关阅读:
    Linux终端复用——tmux
    python中的global和nonlocal
    Pytorch中的错误和bug
    vue之Mutations 理解
    js 对象的合并(3种方法)转载
    json 数组
    vue-cli 安装时 npm 报错 errno -4048
    vue-cli 安装步骤(转载)
    安卓输入框调起键盘后输入框自动上浮
    jquery on 事件嵌套 事件执行多次
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/12852729.html
Copyright © 2011-2022 走看看