Programming Examples
Java program to input 5 real numbers and find their average If the average is greater than 50 print good otherwise print bad
Write a program to input 5 real numbers(floating point) and find their average. If the average is greater than 50 print good, otherwise print bad.
Solution
import java.util.*;
class GoodBad
{
public static void main(String arr[])
{
float a,b,c,d,e,av;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter 5 real numbers:”);
a=sc.nextFloat();
b=sc.nextFloat();
c=sc.nextFloat();
d=sc.nextFloat();
e=sc.nextFloat();
av=(a+b+c+d+e)/5;
System.out.println(“Average=”+av);
if(av>50)
System.out.println(“Good”);
else
System.out.println(“Bad”);
}
}
Output