问答详情
源自:3-8 Java中运算符的优先级

怎么算出x=4的?

int m = 5;

int n = 7;

int x = (m*8/(n+2))%m;

System.out.println("m:" + m);

System.out.println("n:" + n);

System.out.println("x:" + x);


提问者:慕粉0826543674 2018-12-22 14:13

个回答

  • sc123
    2019-03-25 09:55:26

    你们不要误导人啊,%是取模,也就是求余数,40除以9的余数是4,但是巧合是商也是4,麻烦你们不要搞混淆了

  • 慕盖茨8458482
    2019-01-30 15:21:11

    (5*8/(7+2))%5 

    (40/9)%5=4.4444444

    然后int接收就变成4了

  • 慕前端4036223
    2018-12-22 14:57:41

    n+2=9

    m*8=40

    40/9 只要整数4

    4%5=4