Hackerank if else problem with solution --23/7/2022

Task
Given an integer, , perform the following conditional actions:

  • If  is odd, print Weird
  • If  is even and in the inclusive range of  to , print Not Weird
  • If  is even and in the inclusive range of  to , print Weird
  • If  is even and greater than , print Not Weird
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();
         int to_check = n%2;
         if(to_check!=0){
             System.out.println("Weird");
         }
         else if (to_check==0 && n>=2 && n<=5)   {
             System.out.println("Not weird");
         }
         else if (to_check ==0 && n>=6 && n<=20){
             System.out.println("Weird");
         }
         else if (to_check==0 && n>20){
             System.out.println("Not Weird");
         }

    }
}

Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

Learning stage | c++ programs

c++ basic question