Java Reference
In-Depth Information
12.
The insertion-sort algorithm sorts a list of values by repeatedly inserting a new element
into a sorted sublist until the whole list is sorted.
T EST Q UESTIONS
Do the test questions for this chapter online at www.cs.armstrong.edu/liang/intro9e/test.html.
P ROGRAMMING E XERCISES
Sections 6.2-6.5
*6.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
7=
best
-
10
Grade is B if score is
7=
best
-
20
;
Grade is C if score is
7=
best
-
30
;
Grade is D if score is
7=
best
-
40
;
Grade is F otherwise.
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:
Enter 4 scores:
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
4
40 55 70 58
6.2
( Reverse the numbers entered ) Write a program that reads ten integers and dis-
plays them in the reverse of the order in which they were read.
**6.3
( Count occurrence of numbers ) Write a program that reads the integers between 1
and 100 and counts the occurrences of each. Assume the input ends with 0 . Here is
a sample run of the program:
Enter the integers between 1 and 100:
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time
2 5 6 5 4 3 23 43 2 0
Note that if a number occurs more than one time, the plural word “times” is used
in the output.
 
Search WWH ::




Custom Search