반응형
문제
Day 3: Intro to Conditional Statements | HackerRank
Get started with conditional statements.
www.hackerrank.com
문제 설명
정수 n을 입력받는다.
n이 홀수이면 Weird 출력
n이 짝수이고 2~5 사이에 있으면 Not Weird 출력
n이 짝수이고 6~20 사이에 있으면 Weird 출력
n이 짝수이고 20보다 크면 Not Weird 출력
답(Java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); scanner.close(); if (N % 2 == 1) { System.out.print("Weird"); } else { if (N >= 2 && N <= 5) { System.out.print("Not Weird"); } else if (N >= 6 && N <= 20) { System.out.print("Weird"); } else if (N > 20){ System.out.print("Not Weird"); } } } } | cs |
반응형