intro : 주어진 인덱스의 위치의 문자를 출력하는게 포인트, charAt을 이용한다면 쉽게 풀리는 문제
문제
단어 S와 정수 i가 주어졌을 때, S의 i번째 글자를 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 영어 소문자와 대문자로만 이루어진 단어 S가 주어진다. 단어의 길이는 최대 1\,000이다. 둘째 줄에 정수 i가 주어진다. (1 <= i <= |S|)
출력
S의 i번째 글자를 출력한다.
문제 풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
int index = sc.nextInt() - 1;
char ch = input.charAt(index);
sc.close();
System.out.println(ch);
}
}