Input Format

A single line containing a positive integer, .

Constraints

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.


hackerrank java if else solution


Java If Else problem solution | HackerRank

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        try{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine().trim());
        if(N<1||N>100)
            throw new Exception();
        if((N&1)==1)
        {
            System.out.println("Weird");
        }
        else
        {
            if(N>=2&&N<=5)
            {
                System.out.println("Not Weird");
            }
            else if(N>=6&&N<=20)
            {
                System.out.println("Weird");
            }
            else
            {
                System.out.println("Not Weird");
            }
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Second solution

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();            
        String ans;
        if(n%2==1)ans = "Weird";
        else
        {
            if(n>=2 && n<=5)ans = "Not Weird";
            else if(n>=5 && n<=20)ans="Weird";
            else ans = "Not Weird";
        }
        System.out.println(ans);

    }
}