티스토리 뷰

public class Q11 {

    // 양의 정수를 입력하고 자릿수를 출력하는 프로그램
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("자릿수를 구할 양의 정수를 입력하세요.");
        int a;

        do {
            System.out.print("a : ");
            a = scanner.nextInt();
        } while (a <= 0);

        int num = 0;
        while (a > 0) {
            a /= 10;
            num++;
        }

        System.out.println("자릿수 : " + num);
    }
}

- 풀다가 모르겠어서 답 봄

 

※참조
Do it! 자료구조와 함께 배우는 알고리즘 입문

'PS > etc' 카테고리의 다른 글

chapter1) 덧셈표 작성  (0) 2020.07.06
chapter1) 곱셈표 작성  (0) 2020.07.06
chapter1) 두 수의 차 구하기  (0) 2020.07.06
chapter1) 두 정수 사이의 합 구하기  (0) 2020.07.06
chapter1) 가우스의 덧셈  (0) 2020.07.06