We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

If n is odd, print Weird - if 101 or 103 is given should print odd but not for 7
If n is even and in the inclusive range of to 2 and 5, print Not Weird ,enter 2 and 4 not weird and then 3 and 5 weird
If n is even and in the inclusive range of to 6 and 20, print Weird enter 8, 10, 12, 14, 16, 18 should print weird
If n is even and greater than 20 , print Not Weird any number which is even and >20 should print not weird and any number which is not even should print odd like 101, 103, 109 etc...
//********code starts from here **************//

private static final Scanner sc = new Scanner(System.in);

public static void main(String[] args) {
System.out.println("Please enter a number: ");
int number = sc.nextInt();
System.out.println("The number you have entered: " + number);
if((number%2) != 0) {
System.out.println("Wired");
}else if((number%2 != 0) ? (number >=2 && number <=5) : (number >=6 && number <=20)){
System.out.println("Weird");
}else if((number%2 != 0) && (number > 20)) {
System.out.println("Not Wired");
}else {
System.out.println("Not Weird");
}

## Java If-Else

You are viewing a single comment's thread. Return to all comments →

If n is odd, print Weird - if 101 or 103 is given should print odd but not for 7 If n is even and in the inclusive range of to 2 and 5, print Not Weird ,enter 2 and 4 not weird and then 3 and 5 weird If n is even and in the inclusive range of to 6 and 20, print Weird enter 8, 10, 12, 14, 16, 18 should print weird If n is even and greater than 20 , print Not Weird any number which is even and >20 should print not weird and any number which is not even should print odd like 101, 103, 109 etc... //

********code starts from here **************//private static final Scanner sc = new Scanner(System.in);