java重新开始 六(算数操作符)

一、+

1、用于算数计算

2、用于字符串连接

        //+
        int a = 2;
        int b = 3;
        int c = a+b;

        double d = 1.23;
        double e = 2.22;
        double f = d+e;
        double g = f+c;
        //字符串的+是连接
        String h = "g:"+g;
        System.out.println("c = [" + c + "]");
        System.out.println("g = [" + g + "]");
        System.out.println("h = [" + h + "]");

二、-

用于算数运算

        int a = 2;
        int b = 3;
        int c = b-a;

        double d = 1.23D;
        double e = 2.22D;
        double f = e-d;
        double g = f-c;

三、*

用于算数运算

        int a = 2;
        int b = 3;
        int c = b*a;

        double d = 1.23D;
        double e = 2.22D;
        double f = e*d;
        double g = f*c;

四、/

用于算数运算

        int a = 2;
        int b = 3;
        int c = b/a;

        double d = 1.23D;
        double e = 2.22D;
        double f = e/d;
        double g = f/c;

五、%

取余,用于算数运算

        int a = 2;
        int b = 3;
        int c = b%a;

        double d = 1.23D;
        double e = 2.22D;
        double f = e%d;
        double g = f%c;

五、++、--

用于自增、自减

        //自增
        double h = 2.33;
        System.out.println("h1 = [" + (h++) + "]");//使用后自增
        System.out.println("h2 = [" + h + "]");

        //自增
        System.out.println("h3 = [" + (++h) + "]");//使用前自增
        System.out.println("h4 = [" + h + "]");
        /*
          h1 = [2.33]
          h2 = [3.33]
          h3 = [4.33]
          h4 = [4.33]
         */
        //自减
        int i = 3;
        System.out.println("i1 = [" + (i--) + "]");//使用后自增
        System.out.println("i2 = [" + i + "]");

        //自减
        System.out.println("i3 = [" + (--i) + "]");//使用前自增
        System.out.println("i4 = [" + i + "]");
        /*
         i1 = [3]
         i2 = [2]
         i3 = [1]
         i4 = [1]
         */

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值