Basics

Write a Java Program to define a function which accept values of five numbers and calculate sum and average

Write a Java Program to define a function which accept values of five numbers and calculate sum and average.

import java.io.*;
import java.util.*;

class SumAverage
{
	void calculate(int a, int b, int c, int d, int e)
	{
		int s = a + b + c + d + e;
		System.out.println("Sum of five number = " + s );
		int avg = s / 5 ;
		System.out.println("Average of five number = " + avg );
	}
  public static void main(String args[ ])
  {
  	Scanner sc = new Scanner(System.in);
  	int a, b, c, d, e;
  	System.out.println("Enter a =");
  	a = sc.nextInt();
  	System.out.println("Enter b =");
  	b = sc.nextInt();
  	System.out.println("Enter c =");
  	c = sc.nextInt();
  	System.out.println("Enter d =");
  	d = sc.nextInt();
  	System.out.println("Enter e =");
  	e = sc.nextInt();  	
  	SumAverage ob = new SumAverage( );
  	ob.calculate( a, b, c, d, e );
  }
}

Click to comment

Leave a Reply

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

To Top