Programming Examples
Java program to input five integers and find their average
Write a program to input five integers and find their average.
Solution
import java.util.*;
class FindAvg
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
int a,b,c,d,e;
float av;
System.out.println("Enter 5 integers:");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
d=sc.nextInt();
e=sc.nextInt();
av=(float)(a+b+c+d+e)/5;
System.out.println("Average="+av);
}
}
Output