الكود
كود PHP:
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
int lowestScore = 100 /* Make it max score first */, averageScore = 0, counter = 1;
String lowestStudentName = "";
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentsCount = input.nextInt();
if(studentsCount <= 0) System.exit(0);
while(counter <= studentsCount)
{
input.nextLine(); // To discard "\n"
System.out.print("Enter student " + counter + " name: ");
String name = input.nextLine();
System.out.print("Enter student " + counter + " score: ");
int score = input.nextInt();
if(score < lowestScore)
{
lowestScore = score;
lowestStudentName = name;
}
averageScore += score;
counter++;
}
averageScore /= studentsCount;
System.out.println(lowestStudentName + " has the lowest score (" + lowestScore + ") and the average score is " + averageScore);
}
}