📚 Study/Java

JAVA :: Test018_자바의 기본 입출력(System.util.Scanner)

bono-hye 2023. 9. 7. 22:44
import java.util.Scanner;

public class Test018
{
	public static void main(String[] args)
	{
	// 주요 변수 선언
	Scanner sc = new java.util.Scanner(System.in);
	String name;
	int kor, eng, mat, tot;

	// 연산 및 처리
	// - 사용자에게 안내 메세지 출력
	System.out.print("이름 국어 영어 수학 입력(공백 구분) : ");

	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);

	}
}

[Test018 실행 결과]

이름 국어 영어 수학 입력(공백 구분) : 홍길동 90 80 70

>> 이름 : 홍길동
>> 총점 : 240
계속하려면 아무 키나 누르십시오 . . .