zoukankan      html  css  js  c++  java
  • JAVA 基础 /第十二课: 操作符 / JAVA的所有操作符1

    2018-03-07

    一、JAVA的算数操作符

    1.基本算数操作符

    基本的加 减 乘 除:+ - * /

    public class HelloWorld {
        public static void main(String[] args) {
            int i = 10;
            int j = 5;
            int a = i+j;
            int b = i - j;
            int c = i*j;
            int d = i /j;
        }
    }

    2.%取模

    % 取余数,又叫取模......5除以2,余1

    public class HelloWorld {
        public static void main(String[] args) {
     
            int i = 5;
            int j = 2;
            System.out.println(i%j); //输出为1
        }
    }

    3.自增 自减

    在原来的基础上增加1或者减少1:++ 和-- 

    public class HelloWorld {
        public static void main(String[] args) {
     
            int i = 5;
            i++;
            System.out.println(i);//输出为6
     
        }
    }

    自增 自减操作符置前以及置后的区别:

    以++为例 
    int i = 5; 
    i++; 先取值,再运算 
    ++i; 先运算,再取值

    public class HelloWorld {
        public static void main(String[] args) {
            int i = 5;
            System.out.println(i++); //输出5
            System.out.println(i);   //输出6
             
            int j = 5;
            System.out.println(++j); //输出6
            System.out.println(j);   //输出6
        }
    }

    二、JAVA的关系操作符

    1.关系操作符:比较两个变量之间的关系 
    > 大于 
    >= 大于或等于 
    < 小于 
    <= 小于或等于 
    == 是否相等 
    != 是否不等 

    public class HelloWorld {
        public static void main(String[] args) {
           int a = 5;
           int b = 6;
           int c = 5;
            
           System.out.println(a>b);  //返回 false
           System.out.println(a>=c);  //返回 true
            
           System.out.println(a==b); //返回false
           System.out.println(a!=b);//返回true
            
        }
    }
  • 相关阅读:
    如何在EasyDSS内调用的iframe地址设置自动播放?
    雏鹰训练营第一次作业
    211806152 蔡钰玲 http://www.cnblogs.com/211806152Erika/ https://github.com/ErikaSakii
    Python05:while循环
    Python04:简单if逻辑判断
    Python03:用户交互输入格式输出
    Python02:变量
    Python01:HelloWorld
    课后作业(一)
    软工假期预先作业
  • 原文地址:https://www.cnblogs.com/Parker-YuPeng/p/8522385.html
Copyright © 2011-2022 走看看