JAVA
5. JAVA Scanner2
NamGH
2023. 7. 26. 17:49
import java.util.Scanner;
public class Ex04_입력문2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("이름 => ");
String name = sc.next();
System.out.print("국어 점수 => ");
int kor = sc.nextInt();
System.out.print("영어 점수 => ");
int eng = sc.nextInt();
System.out.print("수학 점수 => ");
int math = sc.nextInt();
System.out.println("----------------------");
System.out.printf("이름 : %s\t 국어 :%d\t 영어 :%d\t 수학 :%d\t\n",name, kor, eng, math);
System.out.println("----------------------");
}
}
%c : 문자자
%s : 문자열
%d : 정수
%f : 실수
\n : 줄바꿈
\t : Tab
실수의 경우 %.2f같이 사용하면 소수점 2번째 자리까지만 출력이 가능하다
각각 과목의 점수를 받아 scanner을 이용해 입력한값들이 출력되게 한다