[JAVA] Scannery클래스 예제
1. 이름, 나이, 성별, 국어, 영어, 수학 6가지 정보를 저장할 수 있는 변수를 만들고
2. 총점과 평균(실수로 나타내기)을 포함한 결과를 출력하기
package java03_Scannary;
import java.util.Scanner;
public class ScannaryQuiz {
public static void main(String[] args) {
// (이름, 나이,성별,국어,영어,수학점수) 변수 입력
Scanner sc = new Scanner(System.in)
System.out.println("===== 입력 =====");
System.out.println("Input Name : ");
String name = sc.nextLine();
System.out.println("Input Age : ");
int age = sc.nextInt();
sc.nextLine(); // 개행문자 제거, 이거 안쓰면 출력 오류남 *입력버퍼 오류
System.out.println("Input Gender : " );
String gender = sc.nextLine();
System.out.println("Input Korean : ");
int Korean = sc.nextInt();
System.out.println("Input English : ");
int English = sc.nextInt();
System.out.println("Input Mathmatics: ");
int Mathmatics = sc.nextInt();
System.out.println("===== 출력 =====");
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
System.out.println("성별 : " + gender);
System.out.println("국어 : " + Korean);
System.out.println("영어 : " + English);
System.out.println("수학 : " + Mathmatics);
System.out.println("총점 : " + (English + Korean + Mathmatics));
System.out.println("평균 : " + (double)(English + Korean + Mathmatics)/3);
*강제로 자료형 변환 int -> double *산술연산 몫구하기
sc.close(); // 자원반납, 키보드 사용종료
}//메인 메소드 정의 끝
}//클래스 정의 끝