WAP in Java to print and sum and average of 3 numbers
and display the result
with proper message.
Answers
Answered by
0
Answer:
Program using Scanner class:
import java.util.*;
public class Number
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int a,b,c,sum=0;
double avg=0.0;
sum=a+b+c;
avg=sum/3.0;
System.out.println("The sum of the three numbers="+sum);
System.out.println("The average of the three numbers="+avg);
}
}
Output:
Enter the three numbers
3
6
9
The sum of the three numbers=18
The average of the three numbers=6.0
Program using function argument:
public class Number
{
public static void main(int a,int b,int c)
{
int sum=0;
double avg=0.0;
sum=a+b+c;
avg=sum/3.0;
System.out.println("The sum of the three numbers="+sum);
System.out.println("The average of the three numbers="+avg);
}
}
Similar questions