1926. 간단한 369 게임(JAVA)

semtwo·2023년 4월 27일
0

SW Expert Academy

목록 보기
1/2

1926. 간단한 369 게임

나머지를 이용하여 3, 6, 9 가 나오는 횟수를 카운트하는 방법으로 풀이 했다.

class Solution
{
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
		for(int test_case = 1; test_case <= T; test_case++)
		{
            String str = Integer.toString(test_case);
            int count = 0;
            int n = 0;
            int temp = test_case;
          	for(int i = 0;  i < str.length(); i++){
                n = temp % 10;
                temp /= 10;
                if(n == 3 || n == 6 || n == 9) 
                    count++;
            }
            if(count == 0)
                System.out.print(test_case);
            else{
                while(count >0){
            		System.out.print("-");
                    count -- ;
                }
            }
            System.out.print(" ");
		}
	}
}```
profile
목표는 꾸준히 글쓰기

0개의 댓글