سؤال حلو:
Write a program that reads the total number of students, and each students name and score, and finally displays the name of the student with the lowest score and the average score.
Sample run:
Enter the number of students: 3
Enter student 1 name: Ahmed
Enter student 1 score: 71
Enter student 2 name: Mohammed
Enter student 2 score: 85.5
Enter student 3 name: Abdullah
Enter student 3 score: 94
Ahmed has the lowest score (71) and the average score is 83.5
خطوات الحل:
1- نقوم بتعريف 7 متغيرات، 3 متغيرات String لإدخال أسماء الطلاب، 4 متغيرات من نوع Double لإدخال الدرجات الثلاث وحساب المتوسط،
2- نستخدم السكانر لإدخال القيم إلى المتغيرات
3- نكتب قانون حساب المتوسط
4- نستخدم if statement ونكتب جميع الحالات، وهي:
* إذا كانت الدرجة الثانية أكبر من الثالثة والثالثة أكبر من الأولى (أو) الدرجة الثالثة أكبر من الثانية والثانية أكبر من الأولى ( لاحظوا أننا جمنا الحالتين في جملة واحدة، ونجمعها على أساس إنه الدرجة الاولى أقل درجة مدخلة )
* إذا كانت الدرجة الثالثة أكبر من الأولى والأولى أكبر من الثانية (أو) الدرجة الأولى أكبر من الثالثة والثالثة أكبر من الثانية
* إذا كانت الدرجة الأولى أكبر من الثانية والثانية أكبر من الثالثة (أو) الدرجة الثانية أكبر من الأولى والأولى أكبر من الثالثة
4- نطبع
السورس كود:
كود PHP:
import java.util.*;
public class HomeWork4 {
public static void main(String[] args) {
String student1,student2,student3;
double score1,score2,score3,average=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter student 1 name: ");
student1=input.next();
System.out.println("Enter student 1 score: ");
score1=input.nextDouble();
System.out.println("Enter student 2 name: ");
student2=input.next();
System.out.println("Enter student 2 score: ");
score2=input.nextDouble();
System.out.println("Enter student 3 name: ");
student3=input.next();
System.out.println("Enter student 3 score: ");
score3=input.nextDouble();
average=(score1+score2+score3)/3.0;
if (score2>score3 && score3>score1 || score3>score2 && score2>score1)
System.out.println(student1+" has the lowerst score ("+score1+") and the average score is "+average);
else if (score3>score1 && score1>score2 || score1>score3 && score3>score2)
System.out.println(student2+" has the lowerst score ("+score2+") and the average score is "+average);
else if (score1>score2 && score2>score3 || score2>score1 && score1>score3)
System.out.println(student3+" has the lowerst score ("+score3+") and the average score is "+average);
System.exit(0);
أتمنى إني أكون وفقت في الشرح ،، بالتوفيق للجميع