File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed
memory/repository/computer_programming_2/src/lab02/shoolGrade Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change 11package lab02 .shoolGrade ;
22
3+ import java .util .Scanner ;
4+
35public class StudentMain {
46 public static void main (String [] args ) {
5- Student [] students = {
6- new Student ("철수" , 95 ),
7- new Student ("영희" , 82 ),
8- new Student ("민수" , 67 ),
9- new Student ("지현" , 58 ),
10- new Student ("호준" , 74 )
11- };
7+ Scanner scanner = new Scanner (System .in );
8+ // 학생 수 입력
9+ System .out .print ("학생 수를 입력하세요: " );
10+ int n = scanner .nextInt ();
11+ scanner .nextLine (); // 버퍼 비우기
12+
13+ // 학생 배열 생성
14+ Student [] students = new Student [n ];
15+
16+ // 학생 정보 입력
17+ for (int i = 0 ; i < n ; i ++) {
18+ System .out .print ((i + 1 ) + "번째 학생 이름: " );
19+ String name = scanner .nextLine ();
20+
21+ System .out .print (name + "의 점수: " );
22+ int score = scanner .nextInt ();
23+ scanner .nextLine (); // 버퍼 비우기
24+
25+ students [i ] = new Student (name , score );
26+ }
1227
1328 ClassRoom classRoom = new ClassRoom (students );
1429
You can’t perform that action at this time.
0 commit comments