Java Program to find remainder between 2 numbers

Java Program to find remainder between 2 numbers

Program:-

import java.util.Scanner;

class find_rem{
public static void main(String arg[]){
int num1, num2, rem;
Scanner data = new Scanner(System.in);
// Reading 1st number
System.out.println("Enter 1st number");
num1 = data.nextInt();
//Reading 1st number
System.out.println("Enter 2nd number");
num2 = data.nextInt();
// checking divisor nonzero number
if(num2!=0)
{
// Finding remainder
rem=num1%num2;
// Displaying Remainder
System.out.println("Remainder:"+rem);
}
else
System.out.println("Divisor should be nonzero number");
}
}


Output 1:-

Enter 1st number
5
Enter 2nd number
2
Remainder:1


Output 2:-

Enter 1st number
25
Enter 2nd number
0
Divisor should be nonzero number


Output 3:-

Enter 1st number
258
Enter 2nd number
24
Remainder:18


Output 4:-

Enter 1st number
-58
Enter 2nd number
56
Remainder:-2


Output 5:-

Enter 1st number
51
Enter 2nd number
-85
Remainder:51


Output 6:-

Enter 1st number
-25
Enter 2nd number
-20
Remainder:-5





Learn Java:-
Java codes

Java Programs:-
List of Java Programs

2 Comments

  1. import java.util.*;
    class remainder2
    {
    public static void main (String args[])
    {
    int a,b,c,d;
    Scanner sc = new Scanner(System.in);
    System.out.println ("Enter the first numbers");
    a=sc.nextInt ();
    System.out.println ("Enter the second numbers");
    b=sc.nextInt ();
    c=(a/b);
    System.out.println ("Answer="+c);
    d=(a%b);
    System.out.println ("Remainder="+d);
    }
    }

    ReplyDelete

Add your comments here

Back to Top