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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad