zoukankan      html  css  js  c++  java
  • 8 Java 条件逻辑语句

    ,100 iPhone 11 使

    :

    Java, if else switch .

    1if else

    1if

    if(  ){

            truefalse

    }

    2if

    if(){

              1
    }else{
              2
    }

    3if

    :

    if(1){

          11

    }else if(2){

          22

    }else if(3){

          33

    }else{

          

    }

    4if

    if( 1){
      //// 1true
      if( 2){
        //// 2true
        .... // , ,low
      }
    }

    :

    if{}{}else{}else if(){}使,

    :

    package cn.fage.seven;

    /**
    * @author lin
    * @version 1.0
    * @date 2020-06-24 9:30
    * @Description TODO
    */
    public class TestIf {

       private static TestIf testIf;

       private String name = "";
       private int age = 22;

       public static void main(String[] args) {
           testIf.test1();
           testIf.test2();
           testIf.test3();
           testIf.test4();
      }

       private void test1() {
           if ("".equals(name)) {
               System.out.println(" " + name);
          }
      }

       private void test2() {
           if (age == 18) {
               System.out.println(" " + 18);
          } else {
               System.out.println(" " + 18);
          }
      }

       private void test3() {
           if (age < 15) {
               System.out.println(" 15    ");
          } else if (age < 18) {
               System.out.println(" 18   ");
          } else {
               System.out.println("18  ");
          }
      }

       private void test4() {
           if ("".equals(name)) {
               System.out.println(" " + name);
               if (age == 18) {
                   System.out.println(" " + 18);
              } else {
                   System.out.println(" " + name + " " + 18 + ",  " + age);
              }
          }
      }

    }

    :

     
     18
    18 
     
      18,  22

    2switc

    jdk7String

             

          switch(){
               case 1
                    1
                    break;
               case 2
                    2
                    break;
               case 3
                    3
                    break;
                default:
                    default
                    break;
            }

    defaultbreakswitch

    package cn.fage.seven;

    /**
    * @author lin
    * @version 1.0
    * @date 2020-06-24 9:41
    * @Description TODO
    */
    public class TestSwitch {
       private static TestSwitch testSwitch = new TestSwitch();

       int[] a = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

       public static void main(String[] args) {
           testSwitch.test1();
      }

       private void test1() {
           for (int i : a) {
               test2(i);
          }

      }

       private void test2(int i) {
           int i1 = i % 2;
           switch (i1) {
               case 1:
                   System.out.println(i + " ");
                   break;
               case 0:
                   System.out.println(i + " ");
                   break;
               default:
                   System.out.println(i + " ");
                   break;
          }
      }
    }

    -1 
    0 
    1 
    2 
    3 
    4 
    5 
    6 
    7 
    8 
    9 

     VIP 
      break,switch
                   byte short char int enum(,java5)
      switch VIP 
                                    if   if else

      switch  if

     

  • 相关阅读:
    学习Node.js笔记(一)
    HTML5的新特性及技巧分享总结
    前端切图的一些笔记(整理的有点乱)
    聊一聊前端速度统计(性能统计)那些事儿(转)
    jQuery中的checkbox问题
    随笔记录
    pillow模块快速学习
    Git学习及使用
    网站(陆续更新)
    ggplot笔记001——ggplot2安装
  • 原文地址:https://www.cnblogs.com/naimao/p/13346492.html
Copyright © 2011-2022 走看看