سؤال الفاينل:
Write a program that asks the user to enter Students names followed by their scores and then outputs the following ( Assume Maximum students number is 30 ):
a. Class Average
b. Print Students names who got scores below than the average
c. Print the highest score and print names of students who got the highest score
الحل:
كود PHP:
package finalexam;
import java.util.*;
public class FinalExam {
public static void main(String[] args) {
String[] Names = new String[30];
double[] Scores = new double[30];
double Sum=0,Average=0,Max=Scores[0];
// Entering Values to arrays and calculate average
for (int i=0;i<30;i++)
{
System.out.println("Enter Student ("+(i+1)+") Name: ");
Names[i]=new Scanner(System.in).nextLine();
System.out.println("Enter Student ("+(i+1)+") Score: ");
Scores[i]=new Scanner(System.in).nextDouble();
Sum+=Scores[i];
if (Scores[i]>Max)
Max=Scores[i];
}
Average=Sum/30;
System.out.println("The Average of scores is: "+Average);
// Printing Names of students who has scores less than the average
for (int j=0;j<30;j++)
{
if (Scores[j]<Average)
System.out.println(Names[j]+" Has a score less than the average");
}
// Printing the highest score and the names of students who got the highest scores
System.out.println("The Highest Score is: "+Max);
System.out.println("The Students who got the highest score: ");
for (int z=0;z<30;z++)
{
if (Scores[z]==Max)
System.out.println(Names[z]);
}
} // End of main method
} // End of Class
بالتوفيق للجميع