Java program to calculate average



Java program to calculate average. This java program takes 5 integer input from users with the help of Scanner class and calculates the average. Scanner class is present in util package and its full path can be written as : java.util.Scanner. Before calculating an average of integer, it is typecast-ed to float. Here is the program.

Java program to calculate average

import java.util.*;

class  Average
{
    public static void main(String[] args)
    {
        System.out.println("Enter 5 numbers:");
        Scanner input=new Scanner(System.in);                  //creating Scanner class object, for taking values from user.

        int a,b,c,d,e;

        float avg;

        a=input.nextInt();
        b=input.nextInt();
        c=input.nextInt();
        d=input.nextInt();
        e=input.nextInt();
        avg=(float)(a+b+c+d+e)/5.0;
        System.out.println("Largest Number is: "+avg);
    }
}

Output of Java program to calculate average

Java program to calculate average

Java program to calculate average



"Please Do Like Facebook Page and follow us on Twitter so that you can actively participate and develop skills in programming. If you find above post interesting do share the webpage."
This entry was posted in java and tagged , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>