Java Reference
In-Depth Information
7.
When an array is created, its elements are assigned the default value of 0 for the numeric
primitive data types, \u0000 for char types, and false for boolean types.
8.
Java has a shorthand notation, known as the array initializer , which combines declaring
an array, creating an array, and initializing an array in one statement, using the syntax
elementType[] arrayRefVar = {value0, value1, ..., value k } .
9.
When you pass an array argument to a method, you are actually passing the reference
of the array; that is, the called method can modify the elements in the caller's original
array.
10.
If an array is sorted, binary search is more efficient than linear search for finding an
element in the array.
11.
Selection sort finds the smallest number in the list and swaps it with the first element.
It then finds the smallest number remaining and swaps it with the first element in the
remaining list, and so on, until only a single number remains.
Q UIZ
Answer the quiz for this chapter online at www.cs.armstrong.edu/liang/intro10e/quiz.html .
P ROGRAMMING E XERCISES
Sections 7.2-7.5
*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;
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: 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
7.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.
 
 
Search WWH ::




Custom Search