알고리즘/알고리즘 기초 100제
-
문제9번 - 입력된 수의 각 자릿수 합 구하기알고리즘/알고리즘 기초 100제 2020. 7. 15. 21:55
public class Study9 { /** * 입력된 수의 각 자릿수 합 구하기. * * 1242 * 답) 9 * */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String values = scanner.next(); String[] arr = values.split(""); int sum = 0; for(String str : arr) { sum += Integer.valueOf(str); } System.out.println("각 자릿수 합 : " + sum); } }
-
문제8번 - 팩토리얼 구하기알고리즘/알고리즘 기초 100제 2020. 7. 15. 13:33
public class Study8 { /** * 8번 팩토리얼 * 입력된 수의 팩토리얼을 구하시오 * * 5 * 답) 120 * */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("수를 입력하세요."); int value = scanner.nextInt(); int sum = 1; for(int i=1; i
-
문제 5 - 대소문자 변환알고리즘/알고리즘 기초 100제 2020. 6. 30. 23:36
/** * 대문자는 소문자로, 소문자는 대문자로 변환하세요. helloWorlD -> HELLOwORLd 배열, for, if * */ public class Study5 { public static void main(String[] args) { String compareValue = "helloWorlD"; char[] arr = compareValue.toCharArray(); for(int i=0; i 'a' && arr[i] 'A' && arr[i] 'a' && arr[i] 소문자 a. }else if(arr[i] > 'A' && arr[i] = 65 && arr[i]
-
문제 4번 - 10진수를 2진수로 변환알고리즘/알고리즘 기초 100제 2020. 6. 30. 23:12
10진수를 2진수로 변환하세요. 19 -> 10011출력 public static void main(String[] args) { /* int inputNum = 19; int bin[] = new int[100]; int i = 0; int mok = inputNum; while (mok > 0) { bin[i] = mok % 2; mok /= 2; i++; } i--; for (; i >= 0; i--) { System.out.print(bin[i]); } */ System.out.println(); int value = 0; System.out.println("2보다 큰 수를 입력하시오 : "); Scanner sc = new Scanner(System.in); value = sc.nextInt()..
-
알고리즘 3번 - 최빈수 구하기알고리즘/알고리즘 기초 100제 2020. 6. 21. 23:19
2020-06-21 가장 많이 출현한 수를 출력하시오. 1 2 2 3 1 4 2 2 4 3 5 3 2 정답 : 2 (5회) 배열, For * int형의 기본값이 0 이므로, int형 배열에서도 기본값이 0이라는걸 알았으면 좀더 코드가 단순화 되었을 것 같다. 다시 기억하자 자료형 기본값 int 0 boolean false char '\u0000' bute 0 short 0 long 0L float 0.0f double 0.0d or 0.0 참조형 변수 null public static void main(String[] args) { int[] arr = new int[]{1, 2, 2, 3, 1, 4, 2, 2, 4, 3, 5, 3, 2}; int[] answer = new int[100]; for(in..