Language_Coder 559 : 배열1 - 자가진단5

boom.jun.cho·2022년 5월 17일
0

Language_Coder_JUNGOL

목록 보기
120/197

문제

1반부터 6반까지의 평균점수를 저장한 후 두 반의 반 번호를 입력받아 두 반 평균점수의 합을 출력하는 프로그램을 작성하시오.

반별 평균점수는 초기값으로 1반부터 차례로 85.6 79.5 83.1 80.0 78.2 75.0으로 초기화하고

출력은 소수 두 번째 자리에서 반올림하여 소수 첫째자리까지 한다.

입력

1 3

출력

168.7

코드

package com.jungol.algorithm120;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        float [] ar = {0, 85.6f, 79.5f, 83.1f, 80.0f, 78.2f, 75.0f};

        int firstN = sc.nextInt();
        int secondN = sc.nextInt();

        float sum = ar[firstN] + ar[secondN];
        System.out.printf("%.1f", sum);

        sc.close();
    }
}
	
profile
하루하루 최선을

0개의 댓글