[ Java ][HackerRank] 30 Days of code Day 3

Day 3: Intro to Conditional Statements

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

Complete the stub code provided in your editor to print whether or not is weird.

Input Format

A single line containing a positive integer, .


  • Output Format

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

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

public class Solution {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();

        if(N >= 1 && N <= 100){
            if(N % 2 == 1){
                if(N>=2 && N<=5){
                    System.out.println("Not Weird");
                }else if(N>=6 && N<=20){
                }else if(N>20){
                    System.out.println("Not Weird");


홀수와 짝수를 구하는 문제.

추가로 조건문까지 거는 문제였다.

© 2018. by sora

Powered by sora