JAVA/자바 기본 프로그래밍

Test017 자바의 기본 입출력 java.util.Scanner(퀴즈1)

ready J 2020. 9. 1. 16:35

import java.util.Scanner;

public class Test017
{
	public static void main(String[] args)
	{
		// Scanner 인스턴스 생성
		Scanner sc = new Scanner(System.in);

		// 주요 변수 선언
		String name;				//-- 이름
		int kor, eng, mat, tot;		//-- 국어, 영어, 수학, 총점

		
		// 연산 및 처리
		// ① 사용자에게 안내 메세지 출력
		System.out.print("이름 국어 영어 수학 점수입력(공백구분) : ");
		// 조윤상 90 80 70
		
		// ② 사용자가 입력한 데이터를 각 변수에 담아내기
		name = sc.next();
		kor = sc.nextInt();
		eng = sc.nextInt();
		mat = sc.nextInt();
		
		// ③ 총점 산출
		tot = kor + eng + mat;
		

		// 결과 출력
		System.out.println();
		System.out.println(">> 이름 : " + name);
		System.out.println(">> 총점 : " + tot);


	}
}

//실행 결과
/*
이름 국어 영어 수학 점수입력(공백구분) : 조윤상 90 80 70

>> 이름 : 조윤상
>> 총점 : 240
계속하려면 아무 키나 누르십시오 . . .
*/