5개의 점수(0~10)을 입력받아 최대점수와 최소점수를 뺀 합을 구하는 프로그램
배열을 활용해서 풀어보자
import java.util.Scanner;
public class Ex02_Quiz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int []score = new int[5];
int max, min;
int tot, result;
// 5개의 점수 입력받기
// 점수는 0~10
tot = 0;
for(int i=0; i<5; i++){
do {
System.out.print((i+1)+"번째 점수 : ");
score[i] = sc.nextInt();
} while (score[i]<0 || score[i]>10);
tot+=score[i];
}
max = min = score[0];
// 가장 처음에 입력받은 점수를 max와 min에 넣고 비교한다.
for(int i=1; i<score.length; i++){
if(min>score[i]){
min = score[i];
} else if(max<score[i]) {
max = score[i];
}
}
result = tot - min - max;
System.out.print("점수 리스트 : ");
for(int n: score) {
System.out.print(n+" ");
}
System.out.print("\n취득 점수 : " + result);
sc.close()
}
}
'쌍용강북교육센터 > 7월' 카테고리의 다른 글
0712_Ex04_selection : 선택정렬에 대해 (0) | 2021.07.13 |
---|---|
0712_Ex03_Quiz : 로또 1~45까지 수중 서로 다른 6개의 수 생성 (0) | 2021.07.12 |
! 복습아직 안함 ! 0709_Ex17_calendar : 년, 월을 입력 받아 달력 만들기 (0) | 2021.07.12 |
0709_Ex15_array : 1~10까지 난수를 100개 발생시켜 출력 (0) | 2021.07.12 |
0709_Ex14_array : 배열 선언과 초기화를 동시에 하기 (0) | 2021.07.12 |