Find sum and average of three numbers in java

Write a java program to find sum and average of three numbers and print them respectively.

import java.util.*;
public class sumandavg 
{
    public static void main(String args[])
    {
        Scanner n=new Scanner(System.in);
        int sum=0;
        int a,b,c;
        float avg;
        System.out.println("enter a:");
        a=n.nextInt();
        System.out.println("enter b:");
        b=n.nextInt();
        System.out.println("enter c:");
        c=n.nextInt();
        sum=a+b+c;
        System.out.println("sum is:"+sum);
        avg=(float)(a+b+c)/3;
        System.out.println("avg is:"+avg);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *