
11-01-2012, 09:03 PM
|
 |
|
|
تاريخ التسجيل: Oct 2010
التخصص: CS بإذن واحد أحد
نوع الدراسة: إنتظام
المستوى: الثالث
الجنس: ذكر
المشاركات: 29
|
|
رد: Cpcs 202 شروحات وحلول وواجبات الجافا
حل برنامج الفاينل
كود:
import java.util.*;
public class Final {
public static void main(String[] args) {
String names[] = new String[30];
double scores[] = new double[30];
String low[] = new String[30];
String high[] = new String[30];
double max = 0, sum = 0, ave = 0;
Scanner in = new Scanner(System.in);
for (int i = 0; i < 30; i++) {
System.out.print("Enter student " + (i + 1) + " name: ");
names[i] = in.next();
System.out.print("Enter student " + (i + 1) + " score: ");
scores[i] = in.nextDouble();
sum += scores[i];
ave += sum/30;
if (scores[i] > max) {
max = scores[i];
high[i] = names[i];
}
if (scores[i] < ave)
low[i] = names[i];
}
if (sum > 0)
System.out.println("The average = " + ave);
else
System.out.println("The average is not computable");
System.out.println("Students below the average are: " + Arrays.toString(low));
System.out.println("Students with the highest score are: " + Arrays.toString(high));
}
}
:)
|