Java Program to check given number is divisible by 5

Java Program to check given number is divisible by 5

In this tutorial, you are going to learn writing java program to check whether a given number is divisible by 5 or not.

For example:

Take a number as input from the user.

Suppose a user has given

Input 1:

34

Output will be

Given number is not divisible by 5

Input 2:

45

Output will be

Given number is divisible by 5

Java program to check given number is divisible by 5

import java.util.*;
class Main
{
  public static void main(String args[])
  {
    int num;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the input Number:");
    num=sc.nextInt();
    if(num%5==0){
       System.out.println("Given number is divisible by 5");
    }
    else
    {
       System.out.println("Given number is not divisible by 5");
    }
  }
}

Output

Enter the input Number:
25
Given number is divisible by 5