• java基础-运算符


    1.是什么

    运算符是一些特殊符号,主要用于数学函数、一些类型的赋值语句、逻辑比较方面

    2.赋值运算符(=)

    int a = 10;

    3.算数运算符(+、-、*、/、%)

    public class IntegerDiv {
        public static void main(String[] args) {
            int a = 10;
            int b = 3;
            System.out.println(a / b);
        }
    }
    public class ModCalc {
        public static void main(String[] args) {
            int num = 10;
    
            System.out.println(num % 2);
            System.out.println(num % -3);
            System.out.println(num % 4);
            System.out.println(num % 5);
            System.out.println(num % -6);
        }
    }

    4.比较运算符

    public class CompareOprt {
        public static void main(String[] args) {
            int a = 10;
            int b = 15;
            int c = 10;
    
            System.out.println(a > b);
            System.out.println(a >= b);
            System.out.println(a < b);
            System.out.println(a <= b);
            System.out.println(a != b);
    
            System.out.println(a != c);
            System.out.println(a >= c);
            System.out.println(a <= c);
            System.out.println(a == b);
            System.out.println(a == c);
    
        }
    }

    5.逻辑运算符(与、或、非)

    public class BooleanOprt {
        public static void main(String[] args) {
            boolean a = true;
            boolean b = false;
    
            System.out.println(a && b);
            System.out.println(a & b);
            System.out.println(a || b);
            System.out.println(a | b);
    
            System.out.println(a || (10 / 0 > 1));
            System.out.println(a | (10 / 0 > 1));
    
        }
    }

     

    6.运算符的优先级

    public class PriorityExample {
        public static void main(String[] args) {
            int a = 1 + 3;
            int b = 2;
            boolean both = a > 0 && b > 0;
            System.out.println(both);
    
            boolean result = a < b + 5;
            System.out.println(result);
    
        }
    }

     

     
  • 相关阅读:
    题解 CF171G 【Mysterious numbers
    题解 P1157 【组合的输出】
    题解 P3955 【图书管理员】
    题解 P2036 【Perket】
    题解 CF837A 【Text Volume】
    题解 CF791A 【Bear and Big Brother】
    题解 CF747A 【Display Size】
    题解 P1332 【血色先锋队】
    题解 P2660 【zzc 种田】
    题解 P4470 【[BJWC2018]售票】
  • 原文地址:https://www.cnblogs.com/pangchunlei/p/12199637.html
Copyright © 2020-2023  润新知