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

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