Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = 0, sum = 0; int count = 0; double avg = 0; while (true) { num = sc.nextInt(); if ((0 <= num) && (num <= 100)){ sum += num; count++; } else break; } avg = (double)sum/count; System.out.printf("sum : %d\n", sum); System.out.printf("avg : %.1f", avg); } } | cs |