java program to calculate average of n numbers

Solutions on MaxInterview for java program to calculate average of n numbers by the best coders in the world

showing results for - "java program to calculate average of n numbers"
Alana
30 Jul 2017
1int a, b, c, d;
2		a = 2;
3		b = 3;
4		c = 5;
5		d = 10;
6		System.out.println("Average of n nubers is: " + (a + b + c + d) / 4);
7		// OR
8		Scanner scanner = new Scanner(System.in);
9		System.out.println("Enter 1st number: ");
10		int firstNumber = scanner.nextInt();
11		System.out.println("Enter 2nd number: ");
12		int secondNumber = scanner.nextInt();
13		System.out.println("Enter 3rd number: ");
14		int thirdNumber = scanner.nextInt();
15		System.out.println("Enter 4th number: ");
16		int fourthNumber = scanner.nextInt();
17		System.out.println("Enter 5th number: ");
18		int fifthNumber = scanner.nextInt();
19		System.out.println("Enter 6th number: ");
20		int sixthNumber = scanner.nextInt();
21		System.out.println("Enter Nth number: ");
22		int nthNumber = scanner.nextInt();
23		scanner.close();
24		System.out.println("Average of abouve input numbers is: "
25				+ (firstNumber + secondNumber + thirdNumber + fourthNumber + fifthNumber + sixthNumber + nthNumber)
26						/ 7.0);