728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import java.util.Arrays;
import java.util.Scanner;
public class MainClass2 {
public static void main(String[] args) {
/*
* 학생성적관리 몇명? <- 입력 //2차원배열 과목(이름,국어, 영어, 수학)
총점 평균 수학점수 최고점 영어 점수의 최하점
*
*
* 총점 평균 수학점수 최고점수 영어점수 최하점수
*/
Scanner sc = new Scanner(System.in);
// String student [][] = null;
// 명수 입력
System.out.print("몇명의 학생의 데이터를 등록하시겠습니까? = ");
int count = sc.nextInt();
String student[][] = new String[count][4];
String title[] = { "이름", "국어", "영어", "수학" };
// 데이터 입력을 받을차례
// "이름", "국어", "영어", "수학" 차례대로 입력
// student 배열에 title 배열을 잡아준다.
for (int i = 0; i < student.length; i++) {
for (int j = 0; j < title.length; j++) {// 과목별로 for문을 돌려 편하게 한다.
System.out.print(title[j] + " = ");
String colum = sc.next();
student[i][j] = colum;
}
}
// Arrays.toString 으로 받은 값을 배열을 출력해준다.
for (int i = 0; i < student.length; i++) {
System.out.println(Arrays.toString(student[i]));
}
// 성적 총점
// Integer.parseInt로 문자로 입력된 것을 숫자로 바꿔준다.
int sum = 0;
for (int i = 0; i < student.length; i++) {
for (int j = 1; j < student[i].length; j++) { // 0은 이름이니까 1부터 시작
sum = sum + Integer.parseInt(student[i][j]);
}
}
System.out.println("총점 = " + sum);
// 데이터 탐색
String findName = "이수빈";// 찾고자하는 사람
int index = 0;
for (int i = 0; i < student.length; i++) {
if (student[i][0].contentEquals(findName)) {
index = i;
break;
}
}
System.out.println("index" + index);
// 평균
double avg = 0;
if (student.length > 0) {
avg = sum / student.length;
}
System.out.println("평균 = " + avg);
// 수학점수 최고점수
// 수학은 3번째 임으로 입력값을 student[i][3]로 잡아준다.
int max = 0;
int humanIndex = 0;
for (int i = 0; i < student.length; i++) {
int math = Integer.parseInt(student[i][3]);
if (max < math) {
max = math;
humanIndex = i;
}
}
System.out.println("1등은" + student[humanIndex][0] + "며 점수는" + max + "입니다");
// 수학점수 최소점수
int min = 100;
int humanindex1 = 0;
for (int i = 0; i < student.length; i++) {
int math1 = Integer.parseInt(student[i][3]);
if(min > math1) {
min = math1;
humanindex1 = i;
}
}
System.out.println("꼴등은" + student[humanindex1][0] + "며 점수는" + min + "입니다");
}
}
|
cs |
728x90
'JAVA' 카테고리의 다른 글
8일차//[JAVA] sorting(정렬) 오름차순, 내림차순/데이터를 받아 숫자몇개를 정렬할지~? (0) | 2021.01.20 |
---|---|
8일차// [java] 피보나치 수열 (0) | 2021.01.20 |
자바의 핵심 - 객체지향 프로그래밍(클래스와 객체)1-method (0) | 2021.01.20 |
8일차//[JAVA] 배열 sorting(정렬) 오름차순, 내림차순 (0) | 2021.01.20 |
7일차// [JAVA] Baseball 게임 , 야구게임 (0) | 2021.01.19 |