mercredi 7 avril 2021

Simple If/Else problem with 1/8 test case failed

Simple If-Else problem, please advise:

My objective is as follows:

"Given an integer, n , perform the following conditional actions:

If n is odd, print "Weird"

If n is even and in the inclusive range of 2 to 5, print "Not Weird"

If n is even and in the inclusive range of 6 to 20, print "Weird"

If n is even and greater than 20 , print "Not Weird".

Upon completion, a website that I use automatically checks for all 8 test cases that are involved in this problem in which there is 1 that I got incorrect and all the others correct.

The test case is as follows:

Input(stdin) = 29

Output(stdout) = Not Weird

Expected Output = Weird

This is what I have done so far:

import java.util.regex.*;

public class Solution {



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

    public static void main(String[] args) {
        int N = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        
        if(N % 2 == 0 & N >= 2 & N <= 5){
            System.out.println("Not Weird");
        } else if (N >= 6 & N <= 20){
            System.out.println("Weird");
        } else if (N > 20){
            System.out.println("Not Weird");
        } else {
            System.out.println("Weird");
        }

        scanner.close();
    }
}

Is there anything that I have missed out??

Aucun commentaire:

Enregistrer un commentaire