Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AverageNumber {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberCount = Integer.parseInt(scanner.next()),
- number, sumNumbers = 0;
- for (int i = 0; i < numberCount; i++) {
- number = Integer.parseInt(scanner.next());
- sumNumbers += number;
- }
- double average = 1.0 * sumNumbers / numberCount;
- System.out.printf("%.2f\n", average);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberCount = Integer.parseInt(scanner.next()), sumNumbers = 0;
- for (int i = 0; i < numberCount; i++) {
- sumNumbers += Integer.parseInt(scanner.next());
- }
- System.out.printf("%.2f\n", (double) sumNumbers / numberCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement