From 459f1abe5b6279ef540ae172f90cf7cbc0252810 Mon Sep 17 00:00:00 2001 From: mordiumaco Date: Sun, 12 Jul 2020 23:30:26 +0900 Subject: [PATCH] =?UTF-8?q?1-5=20=EC=86=8C=EC=88=98=20=EB=A7=8C=EB=93=A4?= =?UTF-8?q?=EA=B8=B0=20=EC=97=85=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" | 2 +- .../Solution.java" | 43 +++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git "a/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" "b/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" index 07debf4..88b81df 100644 --- "a/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" +++ "b/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" @@ -2,7 +2,7 @@ * 3. 다음 큰 숫자 * https://programmers.co.kr/learn/courses/30/lessons/12911 */ -class Solution { +class Solution3 { public int solution(int n) { int answer = 0; diff --git "a/week1/5. \354\206\214\354\210\230 \353\247\214\353\223\244\352\270\260/Solution.java" "b/week1/5. \354\206\214\354\210\230 \353\247\214\353\223\244\352\270\260/Solution.java" index cae8dac..d1367c1 100644 --- "a/week1/5. \354\206\214\354\210\230 \353\247\214\353\223\244\352\270\260/Solution.java" +++ "b/week1/5. \354\206\214\354\210\230 \353\247\214\353\223\244\352\270\260/Solution.java" @@ -3,14 +3,49 @@ https://programmers.co.kr/learn/courses/30/lessons/12915 */ -class Solution { +class Solution5 { + + public static void main(String[] args) { + + Solution5 sol1 = new Solution5(); + + int[] nums = { 1, 2, 7, 6, 4 }; + + System.out.println(sol1.solution(nums)); + } public int solution(int[] nums) { - int answer = -1; + int numsLength = nums.length; + + int primeNumberCount = 0; + + for (int i = 0; i < numsLength - 2; i++) { + for (int j = i + 1; j < numsLength - 1; j++) { + for (int k = j + 1; k < numsLength; k++) { + + int total = nums[i] + nums[j] + nums[k]; + if (checkPrimeNumber(total)) { + primeNumberCount++; + } + } + } + } + + return primeNumberCount; + } + + public boolean checkPrimeNumber(int number) { + + boolean checkPrime = true; - System.out.println("Hello Java"); + for (int i = 2; i <= Math.sqrt(number); i++) { + if (number % i == 0) { + checkPrime = false; + return checkPrime; + } + } - return answer; + return checkPrime; } }