smwhee
[코딩도장_문제105] 1~1000에서 각 숫자의 개수 구하기 본문
package codingDojang;
import java.util.Arrays;
/*
* 1~1000에서 각 숫자의 개수 구하기
*
* 예로 10 ~ 15 까지의 각 숫자의 개수를 구해보자
*
* 10 = 1, 0
* 11 = 1, 1
* 12 = 1, 2
* 13 = 1, 3
* 14 = 1, 4
* 15 = 1, 5
*
* 그러므로 이 경우의 답은 0:1개, 1:7개, 2:1개, 3:1개, 4:1개, 5:1개
*/
public class Question_105 {
public static void main(String[] arg) {
String str = "";
char[] cList = null;
int len = 0;
int n = 0;
int[] sumList = new int[10];
for(int i = 1; i <= 1000; i ++) {
str += Integer.toString(i);
}
cList = str.toCharArray();
len = cList.length;
for(int j = 0; j < 10; j++) {
for(int i = 0; i < len; i++) {
n = Integer.parseInt(String.valueOf(cList[i]));
if(n == j) {
++sumList[j];
}
}
System.out.println(j + ": " + sumList[j] + "개");
}
}
}
'Development' 카테고리의 다른 글
[코딩도장_문제120] Dash Insert (0) | 2017.09.26 |
---|---|
[코딩도장_문제106] 10~1000까지 각 숫자 분해하여 곱하기의 전체 합 구하기 (0) | 2017.09.25 |
[코딩도장_문제97] 두 개의 버전을 비교하는 프로그램을 작성하시오. (0) | 2017.09.23 |
[코딩도장_문제96] Printing OXs (0) | 2017.09.22 |
[코딩도장_문제95] h-index & g-index (0) | 2017.09.21 |
![](https://img.linkprice.com/files/glink/lotteon/20220916/8h6AZum4ePQlI_320x50.png)
Comments