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!");
        }
      }
    }
  • 相关阅读:
    python编码小记
    eventlet学习笔记
    python库文件路径
    paste deploy初探
    python浅拷贝与深拷贝
    Javascript basic knowledge
    用大数据学习心理学
    Postgres Database management operations
    Python Socket and WSGI Sample
    Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory错误处理
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/12852729.html
Copyright © 2011-2022 走看看