diff --git "a/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/Solution.java" "b/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/Solution.java" index 0411734..f8b199f 100644 --- "a/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/Solution.java" +++ "b/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/Solution.java" @@ -1,13 +1,19 @@ +import java.util.Arrays; + /* * 1. 하샤드 수 * https://programmers.co.kr/learn/courses/30/lessons/12947 */ class Solution { + public static void main(String[] args) { + Solution solution = new Solution(); + int x = 19; + System.out.println(solution.solution(x)); + } - public boolean solution(int x) { - return false; + public boolean solution(final int x) { + int sum = Arrays.asList(String.valueOf(x).split("")).stream().mapToInt(Integer::parseInt).sum(); + return x % sum == 0 ? true : false; } } - - \ No newline at end of file diff --git "a/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/solution.js" "b/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/solution.js" new file mode 100644 index 0000000..d7b2d6c --- /dev/null +++ "b/week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/solution.js" @@ -0,0 +1,17 @@ +/* + * 1. 하샤드 수 + * https://programmers.co.kr/learn/courses/30/lessons/12947 + */ +class Solution { + static solution = function (x) { + const sum = String(x) + .split("") + .reduce((a, c) => { + return Number(a) + Number(c); + }); + + return x % sum == 0 ? true : false; + }; +} + +console.log(Solution.solution(24)) \ No newline at end of file