Java Program to find average of Three numbers

 import java.util.Scanner;

class Average{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("How many numbers are you goind to add");

int num = sc.nextInt();


int[] numbers = new int[num];

System.out.println("Enter the numbers one by one by pressing enter");


for(int i=0; i<num; i++){

numbers[i] = sc.nextInt();

}

double avg=0;

int sum =0;

for(int i=0; i<num; i++){

sum = sum+numbers[i];


}

avg=sum/num ;

System.out.println("the avg is"+avg);



}

}

Comments

Popular posts from this blog

A simple method using string to check whether the input password is correct or not

Java Program any letter to upper case Letter(JavaSWING) ActionListener

JAVA(String Buffer and String Builder