Algorithm
Problem Name:
In this HackerRank Functions in Java programming problem solution,
In this challenge, we test your knowledge of using if-else conditional statements to automate decision-making processes. An if-else statement has the following logical flow:

Source: Wikipedia
Task
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, printNot WeirdIf n is even and in the inclusive range of 6 to 20, printWeirdIf n is even and greater than 20, printNot WeirdComplete the stub code provided in your editor to print whether or not n is weird.
Input Format
A single line containing a positive integer, n.
Constraints
- 1 <= n <= 100
Output Format
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input 0
3
Sample Output 0
Weird
Code Examples
#1 Code Example with Java Programming
Code -
Java Programming
import java.util.Scanner;
public class Solution{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int a = input.nextInt();
if(a % 2 == 1)
System.out.println("Weird");
else{
if(a >= 6 && a <= 20)
System.out.println("Weird");
else
System.out.println("Not Weird">;
}
}
}
Copy The Code &
Try With Live Editor