lundi 4 octobre 2021

Unable to execute a Java IF-ELSE program in HackerRank

I am solving an IF-ELSE program using JAVA in HackerRank, it executes just fine when I give custom inputs from the console ( i.e 3 and 24 ). But when I try to submit it, it fails all 8 test cases.

https://www.hackerrank.com/challenges/java-if-else/problem

The code:

import java.io.*;
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n%2==0 || n>=2 || n<=5 || n>=0)
        System.out.println("wierd");
    else
        System.out.println("not wierd");
if(n%2==0 && n>=6 && n<=20 && n>20)
        System.out.println("wierd");
    else
        System.out.println("not wierd");
sc.close();
    }
}


output:

Wierd

Not Wierd

Can anyone tell me how to correct my solution?

Aucun commentaire:

Enregistrer un commentaire