Write a java program to accept a number and find out the given number is divisible by 5 or not. If not then print the nearest number from the given number which is divisible by 5
Answers
Answer:
Java Program to Check Whether Given Number is Divisible by 5
public class Check_Divisiblity.
int n;
Scanner s = new Scanner(System.
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");
Answer:
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");
}
}
}
Explanation: