Write a program to find remainder of dividing two numbers, without using % operator? In Java

后端 未结 5 1014
难免孤独
难免孤独 2021-01-03 02:21

How to find the remainder of dividing two numbers without using the modulo operator!! My teacher gave me this exact exercise and It\'s only my 5th lecture in a course calle

5条回答
  •  庸人自扰
    2021-01-03 02:44

    I've just tried this

    public static void main (String [] args){
        int a = 50;
        int b = 9;
    
        int c = a%b;
        int d = a - (a/b)*b;
    
        System.out.println(c);
        System.out.println(d);
    }
    

    And it seems to work. What types are your variables?

提交回复
热议问题