Java Program to find the average of n values passed from command line…

This java code will give you the average of given n values passed from command line.
class Tot_Avg
{
                public static void main(String args[])
                {
                                int i;
                                float a,avg,sum=0;
                                for(i=0;i
                                {
                                                a=Float.parseFloat(args[i]);
                                                sum+=a;
                                }
                                avg=sum/args.length;
                                System.out.println(“Total= “+sum);
                                System.out.println(“Average= “+avg);
                }
}

Add Comment