write a program to input 3 integers and find the difference between their sum and average(full java program)
Answers
Question:-
Write a program in Java to input three integers and find the difference between their sum and average.
Program:-
import java.util.*;
class Number
{
public static void main(String args[])
{
double a,b, c, result;
Scanner sc=new Scanner(System.in);
System.out.println("Enter three numbers. ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
result=(a+b+c)-(a+b+c)/3.0;
System.out.println("Result is: "+result);
}
}
Answer:
Hope this helps
Explanation:
import java.util.*;
public class Difference
{
public static void main(String args[])
{
int a,b, c;
double result;
Scanner sc=new Scanner(System.in);
System.out.println("Enter First number: ");
a=sc.nextInt();
System.out.println("Enter Second number:");
b=sc.nextInt();
System.out.println("Enter third number");
c=sc.nextInt();
result=(a+b+c)-(a+b+c)/3.0;
System.out.println("Result is: "+result);
}
}
output:
Enter First number:
98
Enter Second number:
6
Enter third number
23
Result is: 84.66666666666666