본문 바로가기

알고리즘/Java

(JAVA) 백준 알고리즘 5단계 10039번 : 평균 점수

if, for문 사용하여 사칙연산

int sum=0; 을 스캐너 아래에 썼더니 런탐에러가 떴다.

 

 

소스

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
        int sum = 0;
        Scanner scan = new Scanner(System.in);
        int[] a = new int[5];
        
        for(int i=0; i<5; i++) {
            a[i] = scan.nextInt();
    
            if(a[i]<40){
                a[i]=40;
            }
            sum = sum+a[i];
        }
        int avg = sum/5;
        System.out.println(avg);
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter