[JAVA | 백준 1110] 더하기 사이클
· 테크· Java
Java
백준 1110번 www.acmicpc.net/problem/1110
풀이
두 자리 정수의 합을 일의 자리로, 원래 두 자리 정수를 십의 자리수로 두는 문제이다. 계속해서 원래의 값이 나올 수 있도록 해야 하므로 do-while 문을 이용해서 푼다.
|
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
|
import java.util.Scanner;
public class while_1110 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
int x = input;
int cycle = 0;
do {
x = x%10*10 + (x/10+x%10)%10;
cycle++;
} while(input!=x);
System.out.println(cycle);
}
public static int cnt(int x) {
int t = 1;
if(x/10!=0) {
x=x/10;
t++;
}
return t;
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319