Enter any integer as an input. We use modulus operation to check the divisiblity of given integer by 5. If the given integer gives zero as remainder when divided by 5 then it is divisible by 5 or else its not divisible by 5.
Here is the source code of the Java Program to Check Whether Given Number is Divisible by 5. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Check_Divisiblity
public static void main(String args)
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");
System.out.println(n+" is not divisible by 5");
$ javac Check_Divisiblity.java $ java Check_Divisiblity Enter any number:45 45 is divisible by 5 Enter any number:16 16 is not divisible by 5
Sanfoundry Global Education & Learning Series – 1000 Java Programs.