Programming Examples

Java program to input three integers and find the difference between their sum and their average


Write a java program to input three integers and find the difference between their sum and their average.

Solution

import java.util.*;
class Difference
{
	public static void main(String arr[])
	{
		Scanner sc=new Scanner(System.in);
		int a,b,c,s;
		float av,d;
		System.out.println("Enter 3 integers:");
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		s=a+b+c;
		av=s/3f;
		d=s-av;
		System.out.println("Sum="+s);
		System.out.println("Average="+av);
		System.out.println("Difference b/w Sum and Average = "+d);
	}
}
Output

Enter 3 integers:

4

5

6

Sum=15

Average=5.0

Difference b/w Sum and Average = 10.0

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad