In: Computer Science
In a file called DivisibilityTests.java, write a program that:
For example: if the user enters -5, your program output should look EXACTLY like this:
Please enter an integer: -5 The number is negative.
ANSWER:-
import java.util.*;
public class DivisibilityTests
{
public static void main (String[] args)
{
Scanner sc=new
Scanner(System.in);
System.out.println("Please enter an
integer : ");
int n=sc.nextInt();
if(n<0)
System.out.println("The number is
negative");
else if(n%2==0 &&
n%3==0)
System.out.println("The number is
even and divisible by 3.");
else if(n%2==0 &&
n%3!=0)
System.out.println("The number is
even and not divisible by 3.");
else if(n%2!=0 &&
n%3==0)
System.out.println("The number is
odd and divisible by 3.");
else if(n%2!=0 &&
n%3!=0)
System.out.println("The number is
odd and not divisible by 3.");
}
}
OUTPUT:-
// If any doubt please comment