Write a program in java to accept a number and check whether the number is divisible by 3 as well as 5.Otherwise, decide: (a) Is the number divisible by 3 and not by 5? (b) Is the number divisible by 5 and not by 3? (c) Is the number neither divisible by 3 nor by 5?
Answers
Answered by
64
Answer:
import java.utilis.*;
public static void main (String args[ ]){
Scanner sc = new Scanner;
int a = sc.nextInt();
if(a%3 == 0 && a%5 == 0 )
System.out.println("it is divisible by both");
else if(a%3 == 0 && a%5 != 0)
System.out.println("divisible by 3 and not by 5");
else if(a%3 != 0 && a%5 == 0)
System.out.println("divisible by 5 not by 3");
else
System.out.println("not divisible by both 5 and 3");
}
Answered by
45
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");
}
}
}
=> Output-
$ javac Check_Divisiblity.java
$ java Check_Divisiblity
Enter any number:45
45 is divisible by 5
Enter any number:16
16 is not divisible by 5
Explanation:
Follow me if it helps.
Similar questions