-
Notifications
You must be signed in to change notification settings - Fork 0
강동영 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
강동영 #4
Changes from all commits
0d4fbf8
51cc1fd
6a9a732
9d47cbe
449bb40
1da8fed
ecab455
88e5d06
c3ab003
cf5edf2
616d83e
599ae6c
ac4b73f
701e606
a52f531
4aed798
1b5f5a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.example; | ||
|
|
||
| public class solution2 { | ||
| //평균 구하기 | ||
| public double Solution(int[] arr) { | ||
| int n = arr.length; | ||
| int sum = 0; | ||
| for(int i = 0; i < n; i++) { | ||
| sum += arr[i]; | ||
| } | ||
| double average = (double) sum / n; | ||
| return average; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.example; | ||
|
|
||
| public class solution3 { | ||
| //자릿수 더하기 | ||
| public int solution(int n) { | ||
| int answer = 0; | ||
| String num = String.valueOf(n); | ||
| for(char x : num.toCharArray()) { | ||
| answer += Integer.parseInt(String.valueOf(x)); | ||
| } | ||
| return answer; | ||
| } | ||
| /* | ||
| 1. 정수 n을 문자열로 변환 | ||
| 2. 문자열을 문자 단위로 반복하며 각 문자를 정수로 바꾸고 answer에 누적 | ||
| */ | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.example; | ||
|
|
||
| public class solution4 { | ||
| // 문자열 내 p와 y의 개수 | ||
| public boolean solution(String s) { | ||
| boolean answer = true; | ||
| String py = s.toLowerCase(); | ||
| int p = 0, y = 0; | ||
|
|
||
| for(char x : py.toCharArray()) { | ||
| if(x == 'p') p++; | ||
| if (x == 'y') y++; | ||
| } | ||
| if(p != y) answer = false; | ||
|
|
||
| return answer; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.example; | ||
|
|
||
| public class solution5 { | ||
| //나머지가 1이 되는 수 찾기 | ||
| public int solution(int n) { | ||
| //나머지가 1이 되려면 1보다 커야하므로 2부터 시작 | ||
| for(int i = 2; i < n; i++) { | ||
| if(n % i == 1) return i; | ||
| //수를 찾으면 종료 | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.example; | ||
|
|
||
| public class solution6 { | ||
| //문자열 다루기 기본 | ||
| public boolean solution(String s) { | ||
| boolean answer = true; | ||
| int n = s.length(); | ||
| if(n != 4 && n != 6) return false; //조건 불만족시 종료 | ||
| for(char c : s.toCharArray()) { | ||
| //int 형으로 바꾼 문자가 숫자 범위 바깥이라면 false 반환. | ||
| if( (int) c < 48 || (int) c > 57) return false; | ||
| } | ||
| return answer; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.example; | ||
|
|
||
| public class solution7 { | ||
| public boolean solution(int x) { | ||
| boolean answer = false; | ||
| String num = Integer.toString(x); //문자열로 변환 | ||
| int sum = 0; | ||
| for(char c : num.toCharArray()) { | ||
| sum += (int) c - '0'; //숫자로 변환 | ||
| } | ||
| if(x % sum == 0) answer = true; //하샤드 수인지 확인 | ||
| return answer; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.example; | ||
|
|
||
| public class solution8 { | ||
| //서울에서 김서방 찾기 | ||
| String answer = ""; | ||
| public String solution(String[] seoul) { | ||
| for(int i = 0; i < seoul.length; i++) { | ||
| if(seoul[i].equals("Kim")) { | ||
| return "김서방은 " + i + "에 있다"; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.example; | ||
|
|
||
| public class solution9 { | ||
| //콜라츠 추측 | ||
| public long solution(long num) { | ||
| long answer = 0; | ||
| if(num == 1) return 0; | ||
| while(num != 1) { | ||
| if(answer >= 500) return -1; | ||
| if(num % 2 == 0) num /= 2; | ||
| else num = num*3 + 1; | ||
| answer++; | ||
| } | ||
| return answer; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.valueOf 배우고갑니다 굿