Java Program to Find the Number of Integers Divisible by 5

This is a Java Program to Check Whether Given Number is Divisible by 5.

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.

  1. import java.util.Scanner;
  2. public class Check_Divisiblity
  3. {
  4.     public static void main(String[] args) 
  5.     {
  6.         int n;
  7.         Scanner s = new Scanner(System.in);
  8.         System.out.print("Enter any number:");
  9.         n = s.nextInt();
  10.         if(n % 5 == 0)
  11.         {
  12.             System.out.println(n+" is divisible by 5");
  13.         }
  14.         else
  15.         {
  16.             System.out.println(n+" is not divisible by 5");
  17.         }
  18.     }
  19. }

Output:

$ 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.

advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.