JAVA__47

AMJ·2023년 3월 9일
0

언어_log

목록 보기
47/57
  • nextLine을 활용하여
  • split을 사용해 String[] array 구조로 변환 및 저장
  • array 변환 시 문장구조이기에 정수변환 필요
  • Integer.parseInt(index) > index에 변환하고 싶은 값 투입
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.printf("""
                "4 5" 똑같이 입력하세요.
                """);
        String input = sc.nextLine();
        String[] inputArray = input.split(" ");
        int n1 = Integer.parseInt(inputArray[0]); // inputArray[0] String 이므로 정수 변환
        int n2 = Integer.parseInt(inputArray[1]);



        System.out.printf("출력 : %d\n",n1+n2);
        sc.close(); //scanner 종료
    }
}
profile
재미있는 것들

0개의 댓글