BufferedReader fi = new BufferedReader(new FileReader(“s”)); A) defines a new BufferedReader B) closes a BufferedReader C) opens a file named s and creates a BufferedReader for it D) opens a file called FileReader and creates a BufferedReader for it E) none of the above
What class allows you to open a file for writing? A) FileWriter B) cout C) ofstream D) System.in E) FILE
Which of the following detects an end of a file when reading? A) you check the .eof() method B) you check endOfFile() C) the readln method will return null D) an exception is thrown always thrown at the end of a file E) none of the above
If you create a StringTokenizer object from the string “Hello there in TV Land”, the method countTokens() will return A) null B) 5 C) 4 D) 6 E) none of the above
If you have a printWriter object you can output text to it by using which of the following methods A) readLn B) cout C) println D) printf E) none of the above
Which of the following code snippets will give you the total number of elements in a two-dimensional array called a? A) a.totalsize() B) a.length * a[0].length C) a.getlength() * a.getnextlength() D) a.getcols() * a.getrows() E) none of the above
StringTokenizer is imported with which of the following import directives? A) import javax.util.*; B) import java.util.*; C) java.String.*; D) java.lang.StringTokenizer E) none of the above
What type does the StringTokenizer method nextToken() return? A) int B) boolean C) String D) StringTokenizer E) none of the above
If we define a two dimensional array with 3x3 elements (3 rows and 3 columns), what is the index of the center element of the entire two dimensional array (assume the array is called garply)? Hint: READ THE ANSWERS CAREFULLY! A) garply.[1][1] B) garply[2][2] C) garply[0][0] D) garply.[2][2] E) none of the above
For the following questions write on your answer sheet T if the statement is true, F otherwise
To increment the very first element (first row and first column) in a 2d array called board you could write board[0][0]++;
The StringTokenizer method hasMoreTokens() returns a boolean indicating whether or not there exists more tokens
The following will declare a two dimensional array with 8 elements: int[][] arr = new int[2][6];
To read a line of text from a text file, one uses the cin method
In order to write to a file using a PrintWriter object, you can use the println or print methods
The following code will sum up every element of a two dimensional array (baz) with 3x3 elements
int sum = 0;
for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++) sum+= baz[b][b];
If one created a StringTokenizer from the String “Mr. Casaburi is quite uber-cruel with this quiz” one would get the tokens “Mr.”, “Casaburi”, “is”, “quite”, “uber”, “cruel”, “with”, “this”, “quiz”
“If we do not succeed, then we run the risk of failure”
Implement the method as described below. (Worth 4 points)
Write a method that takes a String as a parameter and returns an int as its result (do NOT use JOptionPane, use return) that returns the number of tokens that exist in the parameter String.