Task Given an integer, , perform the following conditional actions:
If N is odd, print Weird If N is even and in the inclusive range of to , print Not Weird If N is even and in the inclusive range of to , print Weird If N is even and greater than , print Not Weird Complete the stub code provided in your editor to print whether or not is weird.
program:
import java.util.*;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int N = scanner.nextInt();
if(N = odd){
System.out.println("Weird");
} else if(N = even ; 2 < N < 5) {
System.out.println("Not Weird");
} else if(N = even ; 6<N<20 ) {
System.out.println("Weird");
} else{
System.out.println("Not Weird");
}
}
}
You can use modulo %
to check if a number is odd or even. Then use a logical AND &&
for the if conditions.
if(N%2 == 1){
System.out.println("Weird");
} else if(2 < N && N < 5) {
System.out.println("Not Weird");
} else if(6 < N && N < 20) {
System.out.println("Weird");
} else{
System.out.println("Not Weird");
}