WAP to check whether a number is exactly divisible by 5 and 10 using scanner.
1 year ago
OOP Java
Compile code:
import java.util.Scanner;
public class Divisible_by_5_and_10{
public static void main(String[]args)
{
int n,r1,r2;
Scanner s=new Scanner(System.in);
System.out.println("Enter any number:");
n=s. nextInt();
r1=n%5;
r2=n%10;
if(r1==0&&r2==0)
System.out.println("is divisible by both 5 and 10");
else if(r1==0)
System.out.println("is divisible by 5 only but not by 10");
else if(r2==0)
System.out.println("is divisible by 10 only but not by 5");
}
}
Output:
Dipti KC
Jan 8, 2023