• 【Java 基础篇】【第三课】表达式、控制结构


    这两天再看敏捷开发流程,我这个算是敏捷博客吗? 哈哈o(∩_∩)o

      1 package a.b;
      2 
      3 public class Three 
      4 {
      5     static void Expression()
      6     {
      7         System.out.println("一、学习基本的表达式");
      8         
      9         // 数学表达式
     10         System.out.println( 1 + 2 );   //加法
     11         System.out.println( 4 - 3.2 ); //减法
     12         System.out.println( 7 * 1.5); //乘法
     13         System.out.println( 29/7 );   //除法
     14         System.out.println( 29%7 ); //求余
     15         
     16         // 关系表达式
     17         System.out.println(6 > 4.2); //大于
     18         System.out.println(3.4 >= 3.4);  //大于等于
     19         System.out.println(1.5 < 9 ); //小于
     20         System.out.println(    6 <= 1); // 小于等于
     21         System.out.println(2 == 2); //等于
     22         System.out.println(2 != 2 ); //不等于
     23 
     24         /*    
     25         其他的一些表达式
     26         true && false           and
     27         (3 > 1) || (2 == 1)    or
     28         !true                       not
     29  
     30         // 位运算
     31         &                         and
     32         |                          or
     33         ^                         xor
     34         ~                         not
     35         5 << 3                 0b101 left shift 3 bits
     36         6 >> 1                 0b110 right shift 1 bit
     37 
     38         m++                    变量m加1
     39         n--                      变量n减1
     40         condition ? x1 : x2   condition为一个boolean值。根据condition,取x1或x2的值
     41         */
     42     }
     43     
     44     static void Controlstructure()
     45     {
     46         System.out.println("二、学习控制结构");
     47         
     48         int a = 0;
     49         
     50         // 选择语句
     51         if (a == 1) 
     52         {
     53             System.out.println("学习if语句 if ");
     54         }
     55         else if (a == 0) 
     56         {
     57             System.out.println("学习if语句 else if ");
     58         }
     59         else 
     60         {
     61             System.out.println("学习if语句 else ");
     62         }
     63         
     64         // 循环语句
     65         while(a<3)
     66         {    
     67             System.out.println("学习while语句"+a);
     68             a++;
     69         }
     70         
     71         do
     72         {
     73             System.out.println("学习do while语句"+a);
     74             a++;
     75         }while(a<6);
     76         
     77         // 使用break可以跳出循环、使用continue可以直接进入下一循环
     78         for (int i = 0; i < 5; i++)
     79         {
     80             if (i == 1)
     81             {
     82                 continue;                
     83             }
     84             if (i == 4 ) 
     85             {
     86                 break;
     87             }
     88             System.out.println("学习for语句"+i);
     89         }
     90         
     91         // 选择语句
     92         char c = 'b';
     93         switch (c) 
     94         {
     95         case 'a':System.out.println("学习swithch语句"+c); break;
     96         case 'b':System.out.println("学习swithch语句"+c); break;
     97         case 'c':System.out.println("学习swithch语句"+c); break;
     98         default:System.out.println("学习swithch语句 default"); break;
     99         }
    100     }
    101     
    102     
    103     public static void main(String[] args)
    104     {
    105         // 学习基本的表达式
    106         Expression();
    107         
    108         // 学习控制结构
    109         Controlstructure();
    110     }
    111 
    112 }


    运行结果如下:

    一、学习基本的表达式
    3
    0.7999999999999998
    10.5
    4
    1
    true
    true
    true
    false
    true
    false
    二、学习控制结构
    学习if语句 else if 
    学习while语句0
    学习while语句1
    学习while语句2
    学习do while语句3
    学习do while语句4
    学习do while语句5
    学习for语句0
    学习for语句2
    学习for语句3
    学习swithch语句b
    
  • 相关阅读:
    Github 代码在线在vscode中打开
    TP5如何查询字段为空
    浏览器总是报 'https://static.hae123.cn/gc/gc3.js 错误
    Sublime 复制到word 如何保留样式?
    pdf 在浏览器中是下载,而不是打开如何实现?
    Shell脚本中的set指令,比如set -x 和 set -e【转】
    Python面向对象进阶【转】
    Redis为什么变慢了?常见延迟问题定位与分析【转】
    史上最全的 Linux Shell 文本处理工具集锦【转】
    Linux运维常用命令总结【转】
  • 原文地址:https://www.cnblogs.com/by-dream/p/3958554.html
Copyright © 2020-2023  润新知