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.
import java.util.Scanner;
public class Check_Divisiblity
{
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:
$ 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
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Java Books
- Check Programming Books
- Practice BCA MCQs
- Practice Information Technology MCQs
- Apply for Java Internship