Dremendo Tag Line

Find remainder without modulus operator in Java

Input - Question 19

In this question, we will see how to input 2 integer numbers in Java programming using the java input and find out the reminder without using modulus operator (%). To know more about java input click on the java input lesson.

Q19) Write a program in Java to input 2 integer numbers and find out the reminder without using modulus operator (%).

Program

import java.util.Scanner;

public class Q19
{
    public static void main(String args[])
    {
        int a,b,q,r;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 2 integer numbers");
        a=sc.nextInt();
        b=sc.nextInt();
        q=a/b;
        r=a-b*q;
        System.out.print("Remainder=" + r);
    }
}

Output

Enter 2 integer numbers
5
2
Remainder=1                
video-poster