백준 9086번 문자열(java)

마뇽미뇽·2024년 5월 3일
0

알고리즘 문제풀이

목록 보기
45/165

1.문제

https://www.acmicpc.net/problem/9086

2.풀이

문자열을 쪼개 배열에 저장해서 처음과 끝을 출력하였다.

3.코드

import java.util.Scanner;

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

        int n = sc.nextInt();

        for(int i = 0; i < n; i++){
            String s = sc.next();
            String arr[] = s.split("");
            System.out.println(arr[0] + arr[s.length() - 1]);
        }

        sc.close();
    }
}
profile
Que sera, sera

0개의 댓글