Hacker Rank - Day 3 : Intro to Conditional Statements

                        Day 3 :Intro to Conditional Statements.

Solution In Java 8:

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 scan = new Scanner(System.in);
      int n = scan.nextInt();
      scan.close();
      String ans="";
        
      if(n%2==1){
         ans = "Weird";
      }
      else if (n>=2 && n<=5){
             ans = "Not Weird";
      }
      else if (n>=6 && n<=20){
          ans = "Weird";
      }
       else{
           ans = "Not Weird";
       }
      System.out.println(ans);
   }
}

Solution In Python 3: 

import sys
N = int(input().strip())
if N%2!=0:
    print("Weird")
elif N>=2 and N<=5:
    print("Not Weird")
elif N>=6 and N<=20:
    print("Weird")
else:
    print("Not Weird")
Share:

1 comment: