Java Program to find remainder without using modulus operator


In this program, You will learn how to find remainder without using modulus operator in Java.


0 = 10 % 5

5 = 5 % 10


Example: How to find remainder without using modulus operator in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int a,b,q=0;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter Two Numbers :");
        a = sc.nextInt();
        b = sc.nextInt();

       while(a >= b){
           a = a - b;
       }

        System.out.println("\nThe Remainder is :"+a);

    }
}

Output:

Enter Two Numbers :7 3
The Remainder is :1