Overview | Schedule | Announcements | Resources | Assignments | Home |
IMPORTANT: This is a practice exam. We sampled topics from the Final Exam Topics document to give you a sense of the exam that is approaching. Memorizing and/or studying the content of this one, single sample set of practice problems cannot substitute for several weeks of thoroughly studying all the class notes, homework problems, textbook readings, laboratory exercises, and programming projects.
Consider the following field declaration for a class:
String[ ] wordList = new String[100];
Write a method for the class that takes a parameter named word of class String and a parameter named len of type int. The method should return the number of times that word appears in cells 0..len - 1 of the array wordList. (Assume len <= 100)
Consider an array whose contents are:
17 14 8 19 3 12 6 7
Show how this array would look after each step of the Bubble Sort algorithm is carried out.
What output is produced by the following code fragment?
for (int ct = 1; ct <= 3; ct++) { System.out.println(ct); for (int i = 3; i <= 4; i++) { System.out.println(ct + " " + i); } System.out.println("Hi ho"); }
What is the output from the following code fragment?
String sentence = "to be or not to be"; String[ ] words = sentence.split(" "); int len = words.length; for (int pass = 1; pass < len; pass++) { System.out.println("Pass " + pass); for (int i = 0; i < len - pass; i++) { if (words[i].compareTo(words[i + 1]) > 0) { String temp = words[i]; words[i] = words[i + 1]; words[i + 1] = temp; } System.out.println(words[i] + " " + words[i + 1]); } } for (int i = len - 1; i >= 0; i--) { System.out.println(words[i]); }
Questions 5 - 10 refer to the following field declarations for a class called Matrix:
int[ ][ ] grid = new int[10][11]; int[ ][ ] grid2 = new int[10][11];
What output is produced by the following fragment?
for (int row = 1; row <= 2; row++) { for (int col = 1; col <= 3; col++) { grid[row][col] = row + col; } } for (int col = 1; col <= 3; col++) { for (int row = 1; row <= 2; row++) { System.out.print(grid[row][col]); } System.out.println(); }
For the remaining questions in this group, consider the following database table:
firstName | lastName | id | class | GPA | tuition |
---|---|---|---|---|---|
George | Williams | 314159 | 4 | 3.82 | 25000 |
Susanna | Maigret | 271828 | 2 | 3.95 | 26000 |
Alice | Victor | 161803 | 1 | 2.75 | 23000 |
(data omitted) |
Consider the following field declaration
int[ ] myArray = new int[10];
Performing a cyclic shift left on an array means to shift every element of the array one cell to the left. The element that used to be in the first cell (0) of the array becomes the last cell in the array.
For example, if the original array contains the values:
7 5 4 3 8 6 2 4 7 9
The new array would be:
5 4 3 8 6 2 4 7 9 7
Write a method that takes myArray as a parameter and modifies it by performing the cyclic shift left operation on the array.
What output is produced by the following code fragment?
int X = 1; while (X <= 4) { if (X == 1) { X++; System.out.println(X); } else if (X == 2) { X = X + 2; } else if (X == 3) { System.out.println(X + 1); } else if (X == 4) { System.out.println(X * X); X = X + 3 } System.out.println(X); }
Overview | Schedule | Announcements | Resources | Assignments | Home |
DePauw
University , Computer Science
Department , Spring 2005
Maintained by Brian
Howard ( bhoward@depauw.edu
).
Last updated