Five bikers compete in a race such that they drive at a constant speed which may or may not be the same as the other. to qualify the race, the speed of a racer must be more than the average speed of all 5 racers. take as input the speed of each racer and print back the speed of qualifying racers
Answers
import java.util.*;
class BikeRacers
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int speed[]=new int[5];
for(int i=0;i<5;i++)
{
System.out.print("\nEnter the speed of Racer-"+i+": ");
speed[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<5;i++)
sum+=speed[i];
double avg=sum/5;
System.out.print("\nThe speed of qualifying racers is: ");
for(int i=0;i<5;i++)
{
if(speed[i]>=avg)
System.out.print("\nRacer-"+i+": "+speed[i]);
}
}
}
Answer:
import java.io.*;
import java.util.*;
class Bikers
{
static float S1,S2,S3,S4,S5;
static float AvgSpeed;
public static void main(String args[ ])
{
Scanner input = new Scanner(System.in);
System.out.println(" Enter Speed of five Bike Racer");
S1 = input.nextInt();
S2 = input.nextInt();
S3 = input.nextInt();
S4 = input.nextInt();
S5 = input.nextInt();
AvgSpeed=(S1+S2+S2+S3+S4+S5)/5;
if( S1>AvgSpeed)
System.out.println("The Speed of Qualifying Racer is"+S1);
if( S2>AvgSpeed)
System.out.println(" The Speed of Qualifying Racer is"+S2);
if( S3>AvgSpeed)
System.out.println(" The Speed of Qualifying Racer is"+S3);
if( S4>AvgSpeed)
System.out.println(" The Speed of Qualifying Racer is"+S4);
if( S5>AvgSpeed)
System.out.println(" The Speed of Qualifying Racer is"+S5);
}
}
Output:
Enter the speed of Five Bike Racces
56
75
67
78
65
The Speed of the Qualifying Racer is 78
Step-by-step explanation: