Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void inputThenPrintSumAndAverage () {
- Scanner scanner = new Scanner(System.in);
- int count=0;
- int sum=0;
- long avg;
- while (true) {
- if (scanner.hasNextInt()) {
- int num = scanner.nextInt();
- sum += num;
- count++;
- } else {
- avg = (int)Math.round((double)sum / (double)count);
- System.out.println("SUM = " + sum + " AVG = " + avg);
- break;
- }
- }
- }
- public static void main(String[] args) {
- inputThenPrintSumAndAverage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement