From aa27f87f1d600b923f866c9c675af33fc01ed007 Mon Sep 17 00:00:00 2001 From: mordiumaco Date: Mon, 6 Jul 2020 02:12:51 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=98=EC=83=A4=EB=93=9C=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution.java" | 14 ++++++++++---- .../solution.js" | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 "week1/1. \355\225\230\354\203\244\353\223\234 \354\210\230/solution.js" 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