Wap to enter a number which must be >9 and <100 and check if it is divisible by 3 ,5 or both 3 and 5 or not , using nested if .
Answers
The given problem is solved using language Java.
import java.util.Scanner;
public class Brainly{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number (10-99): ");
int n=sc.nextInt();
if(n%5==0){
if(n%3==0)
System.out.println("Number is divisible by both 5 and 3.");
else
System.out.println("Number is divisible by 5 but not by 3.");
}
else if(n%3==0)
System.out.println("Number is divisible by 3 but not by 5.");
else
System.out.println("Number is neither divisible by 3 and 5.");
sc.close();
}
}
#1
Enter a number (10-99): 25
Number is divisible by 5 but not by 3.
———————————————————————
#2
Enter a number (10-99): 12
Number is divisible by 3 but not by 5.
———————————————————————
#3
Enter a number (10-99): 15
Number is divisible by both 5 and 3.
———————————————————————
#4
Enter a number (10-99): 14
Number is neither divisible by 3 and 5.
