๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][27866][๋ฌธ์ž์™€ ๋ฌธ์ž์—ด]

๋‰ด์ด NUEY 2023. 12. 3. 21:39
๋ฐ˜์‘ํ˜•

import java.util.Scanner;

// 27866	๋ฌธ์ž์™€ ๋ฌธ์ž์—ด
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		String letter = in.nextLine();

		char[] arr = letter.toCharArray();
		
		System.out.println(arr[in.nextInt() - 1]);
	}
}

 

  • ๋ฌธ์ž์—ด์„ ๋ฐฐ์—ด๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜ .toCharArray()๋งŒ ์ฐพ์œผ๋‹ˆ ๊ฐ„๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฐฐ์—ด์€ 0๋ฒˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— -1๋กœ ํ•ด๋‹น๊ฐ’์„ ์ฐพ์•„์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•