Check multiple of 5 in Java
if else - Question 5
In this question, we will see how to check if a number is a multiple of 5 or not in Java programming using the if else statement. To know more about if else statement click on the if else statement lesson.
Q5) Write a program in Java to input any number and check if it is multiple of 5 or not. A number is multiple of 5 if it is divisible by 5.
Program
import java.util.Scanner;
public class Q5
{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number ");
n=sc.nextInt();
if(n%5==0)
{
System.out.print("Multiple of 5");
}
else
{
System.out.print("Not Multiple of 5");
}
}
}
Output
Enter a number 10 Multiple of 5