java基础_03

1、常用Java运算符:算术运算符、关系运算符、逻辑运算符 2、算术运算符:+  -  *  /  %   ++  -- 2.1、先算 * / 再算 + -,如果是同级的运算,按照从左到右的顺序。(注意数据类型) 2.2、% 2.3、++ -- 2.3.1、首先,++ 和 -- 的解析方法是一致的,只不过++是+1,--是-1 2.3.2、a++;    ++a;这样单独作用于变量a(没有赋值操作),效果是一样的,都是a += 1; 2.3.3、b = a++;  b = ++a; 这时候++和赋值同时出现时就不同了。++放在前面(++a)a先+1,然后把+1后的值赋值给b; ++放在后面(a++)a先赋值给b,然后a再+1. 3、关系运算符:>   <   >=  <=   !=   == 3.1、关系运算符的运算结果是boolean类型的(boolean类型的值是true或false) 4、逻辑运算符:&&    ||   ! 4.1、逻辑运算符的运算结果是boolean类型的,逻辑运算符参与运算的元素也是boolean类型 4.2、真值表。逻辑与&&的真值表是:只有两个均为true时结果才为true,只要有一个为false或者均为false结果都为false; 逻辑或 ||的真值表是:只要有一个为真或者均为true时结果为true,只有2个均为false时结果才为false 4.3、逻辑与连接的两个boolean类型表达式,按照从左到右的顺序计算。如果左边的运算结果为false,则右边的不需要再进行运算。     逻辑或连接的两个boolean类型表达式,按照从左到右的顺序计算。如果左边的运算结果为true,则右边的不需要再进行运算。

package ThirdDay;

import java.util.Scanner;

public class Max {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("Please input:");
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        if (a > b) {
            if (a > c) {
                System.out.println("Max is a:" + a);
            }
        }
        if (b > a) {
            if (b > c) {
                System.out.println("Max is b:" + b);
            }
        if (c > a) {
            if (c > b) {
                System.out.println("Max is c:" + c);
                }
            }
        }
    }

}
package ThirdDay;

import java.util.Scanner;

public class Max1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("Please input:");
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        if (a > b) {
            if (a > c) {
                System.out.println("Max is a:" + a);
                            }
            else{
                System.out.println("Max is c:" + c);
            }
        }
        else  {
            if (b > c) {
                System.out.println("Max is b:" + b);
            }
            else{
                System.out.println("Max is c:" + c);
            }

        }
    }

}
package ThirdDay;

import java.util.Scanner;

public class Max2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("Please input:");
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        if ((a > b) && (a > c)) {
            System.out.println("Max is a:" + a);
        } else if ((b > a) && (b > c)) {
            System.out.println("Max is b:" + b);
        } else {
            System.out.println("Max is c:" + c);
        }
    }

}
package ThirdDay;

public class TruthTable {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        boolean a = true && true ;
        boolean b = true && false;
        boolean c = false && true;
        boolean d = false && false;
        boolean e = true || true ;
        boolean f = true || false;
        boolean g = false || true;
        boolean h = false || false;
        System.out.println("true && true: " + a);
        System.out.println("true && false: " + b);
        System.out.println("false && true: " + c);
        System.out.println("false && false: " + d);
        System.out.println("true || true: " + e);
        System.out.println("true || false: " + f);
        System.out.println("false || true: " + g);
        System.out.println("false || false: " + h);
    }

}











你可能感兴趣的:(java基础_03)