Hello , here are the code and sample outputs of the problem using for loop , if - else conditions.
Code:-
class game
{
public static void main(String[] args)
{
// integer arrays are
used to store the scores
int []ahmed
={883,132,95};// array of size 3 to store ahmed scores.
int
[]ali={95,116,110};//array of size 3 to store ali scores.
int []
sarah={200,400,300};//array of size 3 to store sarah scores.
float
ahmed_avg=0,ali_avg=0,sarah_avg; // these are the variables to
store the averages.
int
i,ahmed_sum=0,ali_sum=0,sarah_sum=0;// variables to store their
sums.
for (i=0;i<3 ;i++)//
for loop to calculate the sum of their individual scores
{
ahmed_sum=ahmed_sum+ahmed[i];
ali_sum+=ali[i];
sarah_sum+=sarah[i];
}
ahmed_avg=ahmed_sum/3;
// calculate all the averages of their scores
ali_avg=ali_sum/3;
sarah_avg=sarah_sum/3;
System.out.println("The
average score for Ahmed is "+ahmed_avg);
System.out.println("The
average score for Ali is "+ali_avg);
System.out.println("The
average score for sarah is "+sarah_avg);
// if else conditions to
check the highest average and prints them.
if(ahmed_avg>ali_avg
&& ahmed_avg >sarah_avg){
System.out.println("The winner is Ahmed with average high score on
3 rounds as: "+ahmed_avg);
}
else
if(ali_avg>ahmed_avg && ali_avg>sarah_avg){
System.out.println("The winner is Ali with average high score on 3
rounds as: "+ali_avg);
}
else{
System.out.println("The winner is Sarah with average high score on
3 rounds as: "+sarah_avg);
}
}
}
Sample Output:-
rakesh@rakesh:~/Desktop$ javac Chegg.java
rakesh@rakesh:~/Desktop$ java game
The average score for Ahmed is 370.0
The average score for Ali is 107.0
The average score for sarah is 300.0
The winner is Ahmed with average high score on 3 rounds as:
370.0
![class game public static void main(String[] args) // integer arrays are used to store the scores int [lahmed ={883, 132,95};/](http://img.homeworklib.com/questions/c6b37bf0-6ca1-11ec-af39-713a4b7c4ef9.png?x-oss-process=image/resize,w_560)

A group of 3 gamers agreed to compete while playing their favorite game on 3 rounds....