Java运算符一

基础知识

在这里插入图片描述

算术运算符代码一:

package operator;

public class Demon01 {
    public static void main(String[] args) {
        //二元运算符
        //Ctrl +D:复制当前行到下一行
        int a = 30;
        int b = 20;
        int c = 25;
        int d = 25;

        System.out.println(a+b);
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/b);   //1.5-->向下取整是1
        System.out.println(a/(double)b);   //在除出来是小数时一定要注意作用范围
    }
}

算术运算符运行结果一:

D:\environment\java\jdk1.8\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=57253:D:\IntelliJ IDEA 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath D:\environment\java\jdk1.8\jre\lib\charsets.jar;D:\environment\java\jdk1.8\jre\lib\deploy.jar;D:\environment\java\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\environment\java\jdk1.8\jre\lib\ext\cldrdata.jar;D:\environment\java\jdk1.8\jre\lib\ext\dnsns.jar;D:\environment\java\jdk1.8\jre\lib\ext\jaccess.jar;D:\environment\java\jdk1.8\jre\lib\ext\jfxrt.jar;D:\environment\java\jdk1.8\jre\lib\ext\localedata.jar;D:\environment\java\jdk1.8\jre\lib\ext\nashorn.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunec.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\environment\java\jdk1.8\jre\lib\ext\zipfs.jar;D:\environment\java\jdk1.8\jre\lib\javaws.jar;D:\environment\java\jdk1.8\jre\lib\jce.jar;D:\environment\java\jdk1.8\jre\lib\jfr.jar;D:\environment\java\jdk1.8\jre\lib\jfxswt.jar;D:\environment\java\jdk1.8\jre\lib\jsse.jar;D:\environment\java\jdk1.8\jre\lib\management-agent.jar;D:\environment\java\jdk1.8\jre\lib\plugin.jar;D:\environment\java\jdk1.8\jre\lib\resources.jar;D:\environment\java\jdk1.8\jre\lib\rt.jar;E:\桌面\java学习\production\基础语法 operator.Demon01
50
10
600
1
1.5

Process finished with exit code 0

算术运算符代码二

package operator;

public class Demon02 {
    public static void main(String[] args) {
        long a = 1213121212122122L;
        int b = 123;
        short c = 10;
        byte d = 8;
        //如果操作数中的多个数字有一个数字的类型是long,则结果也是long
        //
        System.out.println(a+b+c+d); //long
        System.out.println(b+c+d);   //int
        System.out.println(c+d);     //int
        System.out.println((double)c+d);     //可转
        //System.out.println((String)c+d);     //不可转

    }
}

算术运算符运行结果二

D:\environment\java\jdk1.8\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=57353:D:\IntelliJ IDEA 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath D:\environment\java\jdk1.8\jre\lib\charsets.jar;D:\environment\java\jdk1.8\jre\lib\deploy.jar;D:\environment\java\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\environment\java\jdk1.8\jre\lib\ext\cldrdata.jar;D:\environment\java\jdk1.8\jre\lib\ext\dnsns.jar;D:\environment\java\jdk1.8\jre\lib\ext\jaccess.jar;D:\environment\java\jdk1.8\jre\lib\ext\jfxrt.jar;D:\environment\java\jdk1.8\jre\lib\ext\localedata.jar;D:\environment\java\jdk1.8\jre\lib\ext\nashorn.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunec.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\environment\java\jdk1.8\jre\lib\ext\zipfs.jar;D:\environment\java\jdk1.8\jre\lib\javaws.jar;D:\environment\java\jdk1.8\jre\lib\jce.jar;D:\environment\java\jdk1.8\jre\lib\jfr.jar;D:\environment\java\jdk1.8\jre\lib\jfxswt.jar;D:\environment\java\jdk1.8\jre\lib\jsse.jar;D:\environment\java\jdk1.8\jre\lib\management-agent.jar;D:\environment\java\jdk1.8\jre\lib\plugin.jar;D:\environment\java\jdk1.8\jre\lib\resources.jar;D:\environment\java\jdk1.8\jre\lib\rt.jar;E:\桌面\java学习\production\基础语法 operator.Demon02
1213121212122263
141
18
18.0

Process finished with exit code 0

关系运算符三:

package operator;

public class Demon03 {
    public static void main(String[] args) {
        //关系运算符的结果:正确,错误  布尔值
        int a = 10;
        int b = 20;
        int c = 22;
        // 取余,模运算
        System.out.println(c%a);
        System.out.println(a>b);
        System.out.println(a<b);
        System.out.println(a==b);
        System.out.println(a!=b);

    }
}

关系运算符运算结果三

D:\environment\java\jdk1.8\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=57364:D:\IntelliJ IDEA 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath D:\environment\java\jdk1.8\jre\lib\charsets.jar;D:\environment\java\jdk1.8\jre\lib\deploy.jar;D:\environment\java\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\environment\java\jdk1.8\jre\lib\ext\cldrdata.jar;D:\environment\java\jdk1.8\jre\lib\ext\dnsns.jar;D:\environment\java\jdk1.8\jre\lib\ext\jaccess.jar;D:\environment\java\jdk1.8\jre\lib\ext\jfxrt.jar;D:\environment\java\jdk1.8\jre\lib\ext\localedata.jar;D:\environment\java\jdk1.8\jre\lib\ext\nashorn.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunec.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\environment\java\jdk1.8\jre\lib\ext\zipfs.jar;D:\environment\java\jdk1.8\jre\lib\javaws.jar;D:\environment\java\jdk1.8\jre\lib\jce.jar;D:\environment\java\jdk1.8\jre\lib\jfr.jar;D:\environment\java\jdk1.8\jre\lib\jfxswt.jar;D:\environment\java\jdk1.8\jre\lib\jsse.jar;D:\environment\java\jdk1.8\jre\lib\management-agent.jar;D:\environment\java\jdk1.8\jre\lib\plugin.jar;D:\environment\java\jdk1.8\jre\lib\resources.jar;D:\environment\java\jdk1.8\jre\lib\rt.jar;E:\桌面\java学习\production\基础语法 operator.Demon03
2
false
true
false
true

Process finished with exit code 0

自加,自减区分代码四:

package operator;

public class Demon04 {
    public static void main(String[] args) {
        //++ --,自增 自减 一元运算符
        int a = 3;
        int b = a++;   //执行完这行代码后,先给b赋值,在自增
        //a++  a=a+1;
        System.out.println(b);
        System.out.println(a);
        //++a  a=a+1;
        int c = ++a;   //执行完这行代码前,先自增,再给c赋值
        System.out.println(a);
        System.out.println(c);

        //幂运算2^3  很多计算,我们会使用很多工具类
        double pow = Math.pow(2,3);
        System.out.println(pow);

    }
}

自加,自减区分运行结果四:

D:\environment\java\jdk1.8\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=57388:D:\IntelliJ IDEA 2020.3.2\bin" -Dfile.encoding=UTF-8 -classpath D:\environment\java\jdk1.8\jre\lib\charsets.jar;D:\environment\java\jdk1.8\jre\lib\deploy.jar;D:\environment\java\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\environment\java\jdk1.8\jre\lib\ext\cldrdata.jar;D:\environment\java\jdk1.8\jre\lib\ext\dnsns.jar;D:\environment\java\jdk1.8\jre\lib\ext\jaccess.jar;D:\environment\java\jdk1.8\jre\lib\ext\jfxrt.jar;D:\environment\java\jdk1.8\jre\lib\ext\localedata.jar;D:\environment\java\jdk1.8\jre\lib\ext\nashorn.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunec.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\environment\java\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\environment\java\jdk1.8\jre\lib\ext\zipfs.jar;D:\environment\java\jdk1.8\jre\lib\javaws.jar;D:\environment\java\jdk1.8\jre\lib\jce.jar;D:\environment\java\jdk1.8\jre\lib\jfr.jar;D:\environment\java\jdk1.8\jre\lib\jfxswt.jar;D:\environment\java\jdk1.8\jre\lib\jsse.jar;D:\environment\java\jdk1.8\jre\lib\management-agent.jar;D:\environment\java\jdk1.8\jre\lib\plugin.jar;D:\environment\java\jdk1.8\jre\lib\resources.jar;D:\environment\java\jdk1.8\jre\lib\rt.jar;E:\桌面\java学习\production\基础语法 operator.Demon04
3
4
5
5
8.0

Process finished with exit code 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值