본문 바로가기

프로그래밍/자바

[자바] 정올 128 : 반복제어문1 - 형성평가4

728x90
반응형
SMALL
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i, sum=0, count = 0;
        while(true){
            i = sc.nextInt();
            if(!(i >= 0 && i <= 100)) break;
            sum += i;
            count++;
        }
        double avg = (double)sum / count;
        System.out.println("sum : " + sum);
        System.out.printf("avg : %.1f", avg);

    }
}

728x90
반응형
LIST