Java Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 7: Write a Java program to calculate the average of the n numbers entered by the user.

import java.util.Scanner;

public class Average
	public static void main(String[] args)
		Scanner sc =new Scanner(;
		//Declaring Variables
		int n,num;
		int sum=0; 
		double avg=0;

		System.out.println("Enter the number");
		n = sc.nextInt();
		for(int i=0;i < n;i++)
			System.out.println("Enter Number "+(i+1));
			num = sc.nextInt();
			sum = sum+num;

		System.out.println("Average of the numbers entered: "+avg);

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.