알고리즘/알고리즘 기초 100제

문제 20번 - 369 게임

가다파하 2020. 9. 21. 11:07

문제 : 369 게임 법칙에 맞게 짝을 출력하세요 ( 100번까지)

예) 1 2 짝 4 5 짝 7 8 짝

 

import java.util.*;

public class Youtube20 {
	
	/*
		369 GAME
		~100
	*/
	public static void main(String[] args){
		
		for(int i=1; i<=100; i++) {
			
			String[] arr = String.valueOf(i).split("");

			StringBuilder tempStr = new StringBuilder();
			
			for(String checkStr : arr) {
				if(checkStr.contains("3") || checkStr.contains("6") || checkStr.contains("9")) {
					tempStr.append("ZZAK");				
				}
			}
			
			if(tempStr.toString().isEmpty()){
				System.out.print(i + " ");
			}else{
				System.out.print(tempStr.toString() + " ");
			}
			
		}	
	}
}