wap to accept a number and check (a)is it divisible by three and not by five b.is it divisible by five and not by three c.is it not divisible by five nor three(program should be done in java)
Answers
Answered by
2
Answer:
import java.util.*;
public class Divisibility
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a;
System.out.println("Enter the number");
a=in.nextInt();
if(a%3==0&&a%5==0)
{
System.out.println("The number is divisible by 3 as well by 5");
}
else if(a%3==0&&a%5!=0)
{
System.out.println("The number is divisible by 3 and not by 5");
}
else if(a%3!=0&&a%5==0)
{
System.out.println("The number is divisible by 5 and not by 3);
}
else if(a%3!=0&&a%5!=0) /*This bolded statement is optional you can write or leave it */
{
System.out.println("The number is neither divisible by 3 nor by 5");
}
}
}
Output
Enter the number
27
The number is divisible by 3 and not by 5
Similar questions