Advertisement
svephoto

Average Number

Nov 13th, 2019
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AverageNumber {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int number = Integer.parseInt(scanner.nextLine());
  8. int sum = 0;
  9.  
  10. for (int i = 0; i < number; i++) {
  11. int currentNumber = Integer.parseInt(scanner.nextLine());
  12. sum += currentNumber;
  13. }
  14.  
  15. double average = sum * 1.0 / number;
  16. System.out.printf("%.2f%n", average);
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement