728x90
띠용,, 파이썬만 하다보니
;
{}
if문 조건문은 ()에 넣기 등등을 빼먹어서
괜히 시간 쓴 문제ㅠㅠ
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, , perform the following conditional actions:
- If is odd, print Weird
- If is even and in the inclusive range of 2 to 5, print Not Weird
- If is even and in the inclusive range of 6 to 20, print Weird
- If is even and greater than 20, 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, .
Constraints
- 1 <= n <= 100
풀이>
주어진 알고리즘대로 if A Then B, Else C 구조로 가야하기 때문에 다음과 같이 풀었다.
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 {
/*
If is odd, print Weird
If is even and in the inclusive range of 2to5 , print Not Weird
If is even and in the inclusive range of 6to20 , print Weird
If is even and greater than 20, print Not Weird
*/
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])?");
if (N%2 == 0 && (N>=2 && N<=5 || N>20)){
System.out.println("Not Weird");
}else{
System.out.println("Weird");
}
scanner.close();
}
}
'매일매일 코딩연습! > Hackerrank' 카테고리의 다른 글
해커랭크3. Java Output Formatting (0) | 2021.02.12 |
---|---|
해커랭크2. Java Stdin and Stdout Ⅱ (0) | 2021.02.10 |