프로그래머스 코딩(자바)/Coding dojang
고집수 구하기
kjwc
2023. 3. 30. 17:12
728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/*
고집수란??
- 10 ~ 99까지 두 자리 수의 각 자리수를 분할하여 곱합니다.
- 그 곱한 수를 마찬가지로 분할하여 다시 곱해주고 이 과정을 반복해서 1의 자리수로 만듭니다.
- 이렇게 곱해 나가는 반복 '횟수'를 고집수라고 하며 출력형식과 같이
고집수가 4이상 되는 수들만 출력합니다.
ex) 77 -> 49 -> 36 -> 18 ->8 (고집수, 반복횟수 4회),
96 -> 54 -> 20 -> 0 (고집수 아님, 반복횟수 3회)
*/
public class Ex10 {
public static void main(String[] args) {
for(int i=10;i<100;i++) {
int count=0;
int temp = i;
//System.out.print(i + " : ");
while(temp>=10) {
//System.out.print((temp/10) * (temp%10) + "->");
temp = (temp/10) * (temp%10);
count++;
} // end while
System.out.println();
if(count>=4) {
System.out.println(i + "는 고집수 : 반복횟수는 " + count);
}// end if
}// end for
}// end main
}// end class
|
cs |
728x90