## Saturday, 20 August 2016

### Chapter 7 Exercise 1, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

*7.1 (Assign grades) Write a program that reads student scores, gets the best score, and then assigns grades based on the following scheme:
Grade is A if score is Ú best - 10
Grade is B if score is Ú best - 20;
Grade is C if score is Ú best - 30;
Grade is D if score is Ú best - 40;

The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Here is a sample run:

Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B

import java.util.Scanner;

public class ProgrammingEx7_1 {

public static void main(String[] args) {
System.out.print("Enter the number of students:");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] score = new int[n];
int bestScore = 0;

System.out.print("Enter " + n + " scores:");

for (int i = 0; i < score.length; i++) {
score[i] = input.nextInt();
if (bestScore < score[i]) {
bestScore = score[i];
}
}

for (int i = 0; i < score.length; i++) {
if (score[i] >= bestScore - 10)
else if (score[i] >= bestScore - 20)
else if (score[i] >= bestScore - 30)
else if (score[i] >= bestScore - 40)
else