본문 바로가기

백준 문제풀기/JAVA

[백준 27866 JAVA 자바] 문자와 문자열

문자열 str과 숫자 i를 입력받아

 

문자열의 i번째 글자를 출력합시다

 

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

        String str = scan.nextLine();
        
        int a = scan.nextInt();
        
        System.out.print(str.charAt(a-1));
        
	}

}

str.charAt(i)는 i 번째 char를 출력해줍니다