문제
문자열을 입력으로 주면 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램을 작성하시오.
https://www.acmicpc.net/problem/9086
코드
간단히 입출력을 받는 문제라 따로 해설을 적진 않겠다!
import java.util.Scanner;
public class B_9086 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
for(int i=0; i<n; i++){
String s = sc.next(); // 문자열 입력
char first = s.charAt(0); // 첫 번째 문자
char last = s.charAt(s.length() - 1); // 마지막 문자
// 문자를 문자열로 변환하여 출력
System.out.println(first + "" + last);
}
}
}
결과

'알고리즘' 카테고리의 다른 글
[프로그래머스] -PCCE 기출문제 9번 / 지폐 접기 (4) | 2025.04.25 |
---|---|
[프로그래머스] - PCCP 기출문제 1 (0) | 2025.04.25 |
[백준] - 10810번 (0) | 2025.04.25 |
[백준] - 2480번 (0) | 2025.04.25 |
[백준]- 2225번 (0) | 2025.04.25 |