Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

잉여의 IT

[백준 1436번: 영화감독 숌] 자바 문제풀이 본문

백준 풀이

[백준 1436번: 영화감독 숌] 자바 문제풀이

프로잉여 2022. 7. 21. 00:51

숫자를 문자열로 변환하는 방법을 알면 쉽게 푸는 간단한 문제이다.

숫자를 문자열로 변환한 후 그 문자열에 "666"이 포함되어 있는지를 검사만하면 된다. 

반복문은 쉽게 While(true)를 이용하였다.

 

*자바에서 숫자를 문자열로 변환하는 방법

1) String s = Integer.toSring(i);

2) String s = String.valueOf(i);

 

import java.util.Scanner;
public class Main {
	
	int Search(int N) {
		int i=0;
		int count=0;
		while(true) {
			if(Integer.toString(i).contains("666")) {
				count++;
			}
			if(count==N)
				return i;
			i++;
		}
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main Main = new Main();
		
		int N = sc.nextInt();
		
		System.out.println(Main.Search(N));
		sc.close();
	}

}
Comments