Check If Number is Divisible by 5 Java

Given number is divisible by 5 in java. Enter any integer as an input for this Java program to check if a given number is divisible by 5. To check the divisibility of a given integer by 5, we use the modulus operation. If the given integer divides by 5 with zero as a remainder, it is divisible by 5; otherwise, it is not divisible by 5.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
if(n % 5 == 0)
{
System.out.println(n+" is divisible by 5");
}
else
{
System.out.println(n+" is not divisible by 5");
}
}
}

 

Output:

Enter any number:45
45 is divisible by 5

Division Number in Java

Division is one of the four basic mathematical operations, with addition, subtraction, and multiplication being the other three. Simply said, division is the process of dividing a large group into equal smaller units.

Uses of Modulo Operator in Java

After division, the Modulo or Remainder Operator returns the remainder of the two numbers. If you’re given two numbers, say A and B, where A is the dividend and B is the divisor, is there a residue of A and B’s division? The modulo operator is an arithmetic operator indicated by the letter percent.