算术运算符

//测试算术运算符: + - + - * / % ++ -- +
class TestAri{
    public static void main(String[] args){
        
        // 除:/
        int i = 12;
        int j = i/5;
        double d = i / 5;
        double d1 = i/5.0;
        System.out.println(j);//2
        System.out.println(d);//2.0
        System.out.println(d1);//2.4
        //取模:%:取余数. 结果的符号取决于被模数
        int i1 = 12 % 5;
        int i2 = -12 % 5;
        int i3 = 12 % (-5);
        int i4 = -12 % (-5);
        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println(i4);
        //前++:先自增1,后做运算
        //后++:先做运算,后自增1

        int myInt1 = 10;
        int myInt2 = myInt1++;//后++
        System.out.println(myInt1);//11
        System.out.println(myInt2);//10

        int myInt3 = 10;
        int myInt4 = ++myInt3;//前++
        System.out.println(myInt3);//11
        System.out.println(myInt4);//11

        //前--:先自减1,后做运算
        //后--:先做运算,后自减1

    }
}
View Code

输入结果:

2
2.0
2.4
2
-2
2
-2
11
10
11
11

转载于:https://www.cnblogs.com/wangmengge/p/8628874.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值