Java Remainder of Integer Divison?

后端 未结 5 1300
甜味超标
甜味超标 2021-01-18 01:44

I was searching around about this topic but I still don\'t get it, if someone can elaborate I would be very thankful.

My task is to divide two variables as integer d

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 02:36

    If you are looking for the mathematical modulo operation you could use

    int x = -22;
    int y = 24;
    System.out.println(Math.floorMod(x, y));
    

    If you are not interested in the mathematical modulo (just the remainder) then you could use

    int x = -22;
    int y = 24;
    System.out.println(x%y);
    

提交回复
热议问题