[자바 반복문] 24. While문 (점수 평균 구하기)

김건우's avatar
Feb 05, 2025
[자바 반복문] 24. While문 (점수 평균 구하기)
package ex03; import java.util.Scanner; public class Prc03 { public static void main(String[] args) { int total = 0, count = 0; Scanner sc = new Scanner(System.in); while (true) { System.out.println("점수를 입력하시오: "); int grade = sc.nextInt(); if (grade < 0) break; total += grade; count++; } System.out.println("평균은 " + total / count); } }
notion image
Share article

gunwoo