Saturday, 3 September 2011

Variable Length array in java


class abc
{
public static void main(String args[])
{
System.out.print(average(45,46.9,12,44,5,7,3,8));
}
public static double average(double...num)
{
double total=0,avg;
for(double x:num)
total+=x;

avg=total/num.length;
return avg;
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.