The program finds the average of numbers in an array.

Program Code:
class Avg
{
public static void main(String args[])
{
int n=args.length;
float [] x=new float[n];
for(int i=0; i<n; i++)
{
x[i]=Float.parseFloat( args[i]);
}
float sum=0;
for(int i=0; i<n; i++)
sum=sum+x[i];
float avg=sum/n;
System.out.println("Average of given numbers is "+avg);
}
}

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: