Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion week1/3. 다음 큰 숫자/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 39 additions & 4 deletions week1/5. 소수 만들기/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제곱근까지만 반복문을 돌리는방법은 매우 훌륭한것 같습니다!

if (number % i == 0) {
checkPrime = false;
return checkPrime;
}
}

return answer;
return checkPrime;
}

}