zoukankan      html  css  js  c++  java
  • java001-java基础

    基础数据类型

    int--->Integer

    long--->Long

    float--->Float

    double--->Double

    boolean--->Boolean

    char[]--->String

    数组

    基本类型的一组数据,使用数组来表示

    int[] arrs = new int[5];

    数据越界问题--QA需注意的点

    流程控制

    if...else if....else

    public void testIf() {
        /**
         * if…else if…else
         *
         */
    
        boolean bool = true;
        if (bool) {
          System.out.println("Demo2.main is true");
        } else {
          System.out.println("Demo2.main is false");
        }
    
        String str = "";
    
        if (str.equals("a")) {
          System.out.println("Demo2.main a");
        } else if (str.equals("b")) {
          System.out.println("Demo2.main b");
        } else if (str.equals("C")) {
          System.out.println("Demo2.main b");
        } else {
          System.out.println("Demo2.main default");
        }
    
        // qa关注的
        if (str.equals("a")) {
          System.out.println("Demo2.main a");
        } else if (str.equals("b")) {
          System.out.println("Demo2.main b");
        } else if (str.equals("C")) {
          System.out.println("Demo2.main b");
        }
    
        // .....
    
      }

    switch-case

    public void testSwitch() {
    
        String str = "";
    
        switch (str) {
          case "A":
            System.out.println("Demo2.testSwitch,A");
            break;
          case "B":
            System.out.println("Demo2.testSwitch , B");
          default://QA需注意的地方
            System.out.println("Demo2.testSwitch, C");
        }
    
      }

    for

    public void testFor() {
    
        for (int i = 0, j = 1024; i < 10; i++) {
          // 使用j,
          if (i == 5) {
            continue;
          }
    
          System.out.println(i);
        }
    
        String str = "";
    
        for (; ; ) {
          // 见到死循环,不要慌, 一定要去看 退出条件。
    
          if (str.equals("abc")) {
            break;
          }
    
          System.out.println("");
        }
    
        // 调用外部的接口
        int i = 0;
    
        for (; ; ) {
          // send http
          // response == null catch timeout exception
          i = i + 1;
          if (i > 3) {
            break;
          }
        }
    
      }

    while

        public void testWhile(boolean b) {
    //        while (b){
    //            System.out.println("dfjldskfs");
    //        }
            int i = 0;
            while (true){
                i++;
                if (i>10){
                    break;
                }
            }
        }

    continue,break,return

    运算符

    • 算术运算:+,-,*,/,++,
    • 赋值运算:=,+=,-=
    • 比较运算:==,!=,<,>,<=,>=
    • 逻辑运算:&&,||,!
    • 三元运算:statement?val1:val2;
    public static void main(String[] args) {
        /**
         * 算术运算: +,-,*,/,++,–-
         * 赋值运算: =,+=,-=
         * 比较运算: ==,!=,<,>,<=,>=
         * 逻辑运算: &&,||,!
         * 三元运算: statement?val1:val2;
         */
    
        // 注意区别
        int i = 1024;
        i++;  // 先加
        ++i;  // 先用
    
        // == 和 =
        int b = 2048;
        if (b == i) {
    
        }
    
        // == 与 equals的区别
        Integer i1 = 1024;
        Integer i2 = 1024;
        if (i1 == i2) {
    
        }
    
        // && 所有表达式都为true,结果才为true
        // || 只要有一个为true, 结果就是true
        // if (statement1 && stemenet2 && stement3)
    
    
        // 三元运算: statement?val1:val2;
    //    if (statement){
    //      return val1;
    //    }else {
    //      return val2;
    //    }
    
      }
    

      

  • 相关阅读:
    php apc 安装
    apaache php 日记设计
    memcache windows64 位安装
    JavaScript的作用域与闭包
    怎样写一个简单的操作系统?
    php 关于锁的一些看法
    Windows版本Apache+php的Xhprof应用__[2]
    Windows版本Apache+php的Xhprof应用
    使用TortoiseGit对Git版本进行分支操作
    机器学习数据不均衡问题
  • 原文地址:https://www.cnblogs.com/cjxxl1213/p/14890934.html
Copyright © 2011-2022 走看看