• 大龄屌丝自学笔记Java零基础到菜鸟010


    选择结构:if...else... , switch...case...

    1、if...else...格式1:

     1 class Fin{
     2     public static void main(String[] args){
     3         int a=1;
     4 
     5         if(a==1){
     6             a=2;
     7         }
     8     }
     9 }
    10 
    11 //a等于2

    2、if...else...格式2:

     1 class Fin{
     2     public static void main(String[] args){
     3         int a=1;
     4         int b=2;
     5         int c;
     6     
     7         if(a>=b){
     8             c=a;
     9         }else{
    10             c=b;
    11         }
    12     }
    13 }
    14 
    15 //c等于2

    3、if...else...格式3:

     1 class Fin{
     2     public static void main(String[] args){
     3         int a=1;
     4         int b=2;
     5         int c;
     6     
     7         if(a>b){
     8             c=a;
     9         }else if(a<b){
    10             c=b;
    11         }else{
    12             c=3;
    13         }
    14     }
    15 }
    16 
    17 //c等于2, “if” 、 “else” 只能有一个, “else if” 可以有多个

    4、switch...case...

     1 class Fin{
     2     public static void main(String[] args){
     3         int a=2;  //byte、short、int、char、枚举(JDK5)、String(JDK7)
     4         int b;    
     5 
     6         switch(a){
     7             case 0:
     8                 b=1;
     9                 break;
    10             case 1:
    11                 b=8;
    12                 break;
    13             case 2:
    14                 b=9;
    15                 break;
    16             default:
    17                 b=2;
    18                 break;
    19         }
    20     }
    21 }
    22 
    23 //b等于9,case后边只能是常量,不能是变量;case可以有多个,但多个case后的不能相同
  • 相关阅读:
    微信小程序中的组件使用1
    小程序中的请求封装
    路由
    nodejs静态web服务
    跨端开发小程序
    非阻塞I/O事件驱动
    Node文件模块
    提炼游戏引擎系列:初步设计引擎
    提炼游戏引擎系列:开篇介绍
    发布HTML5 2D游戏引擎YEngine2D
  • 原文地址:https://www.cnblogs.com/liverpool/p/4755982.html
Copyright © 2020-2023  润新知