백준 1110 - 더하기 사이클 (자바)

남현·2025년 11월 14일

백준

목록 보기
8/16

문제

풀이

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = N;
        int count = 0;
        while(true) {
            int a = T / 10; // 첫번 째 추출
            int b = T % 10; // 두번 째 추출
            int c = (a + b) % 10;
            T = (b*10) + c;
            count++;
            if(N == T) {
                break;
            }
        }
        System.out.print(count);
        sc.close();
    }
}

한 번은 무조건 실행하고 조건을 만족하면 멈추니 do while 문이 더 적합하다.

profile
백엔드 호소인

0개의 댓글