








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Class: CS 160 - Foundations in Programming; Subject: Computer Science; University: Colorado State University; Term: Fall 2015;
Typology: Quizzes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









How do you get the size of a linked list. size() TERM 2 What is the best way to declare a linked list of String objects? DEFINITION 2 LinkedListlist=new LinkedList(); TERM 3 Assuming list is a LinkedList of String objects that contains the following: [A, B, C, D, E, F]. list.add("D".3) would add "D" at the 4th index in the linked list. DEFINITION 3 False TERM 4 Assuming list is a LinkedList of String objects that contains the following: [A, B, C, D, E, F]. list.get("C") would fetch the index of the first occurrence of "C" in the linked list. DEFINITION 4 True TERM 5 LinkList with ["A", "B", "C", "D"]. Code that puts "G" at the first position (0th index) in list. DEFINITION 5 list.addFirst("G")
T/F - The LinkedList class in Java is located at java.lang.LinkedList. False TERM 7 LinkList with ["A", "B", "C", "D"].What expression would return a boolean expression if the list has "A"? DEFINITION 7 list.contains("A"); TERM 8 T?F - Calling the recursive method infinitely will lead to a stack overflow exception. DEFINITION 8 True TERM 9 T/F - The recursive call(s) to a method must be located outside the method body. DEFINITION 9 False TERM 10 T/F - Any recursive method can be implemented using an iterative approach (using loops). DEFINITION 10 True
Array lists you specify the type of elements it will contain. can store any type of Object have a size method that is the number of elements in the list. TERM 17 Interfaces contain, and can be created with what DEFINITION 17 Contain a list of methods a class promises to implement.here are only method stubs in the interface.We can create an ArrayList of an interface typeWe can create an array of an interface type TERM 18 Is it a compile-time or run-time error exception because of an out of bounds array access? DEFINITION 18 compile-time TERM 19 How can programers handle Checked Exception DEFINITION 19 The exception may be handled in a try/catch blockThe exception may be thrown to the calling method TERM 20 In recursion, a helper method is required when: DEFINITION 20 The original call does not carry enough information
Which line of code creates a PrintWriter to write a file named "output.txt"? PrintWriter out = new PrintWriter (new File("output.txt")); TERM 22 What method must a class implement if the class implements Comparable? DEFINITION 22 compareTo TERM 23 What is the purpose of the finally clause with exception? DEFINITION 23 To provide code that is run whether an exception is caught or not. TERM 24 T/F - A recursive method is said to be tail recursive if there are pending operations to be performed on return from a recursive call. DEFINITION 24 False TERM 25 ArrayList of String objects named arr. How do you fetch the number of strings in arr? DEFINITION 25 arr.size()
T/F - Anything that can be accomplished using a while loop, can also be done using a for loop or a do-while loop. True TERM 32 T/F - There is no difference between if(true){ ____ } and while(){ ____ }. DEFINITION 32 false TERM 33 T/F - Any switch statement can be replicated using an if/else if/else statement. DEFINITION 33 True TERM 34 T/F - An if statement must always be followed by an else to specify what happens when the condition is false. DEFINITION 34 False TERM 35 T/F - A do-while loop is executed at least once. DEFINITION 35 True
What variable of type int without type casting? byte TERM 37 Name the 8 primitive types DEFINITION 37 char, int, double, float, long, short, byte, boolean TERM 38 or(int i=0;i DEFINITION 38 051015 TERM 39 The digital signature of a method refers to: DEFINITION 39 The name of the method and the types of the parameters. TERM 40 int x = 15 | 6; What is x equal to? DEFINITION 40 15
What does this print? System.out.printf(%.3f\n, 3.1415);
TERM 47 What does this print? System.out.printf(%.4f\n, 3.1); DEFINITION 47
TERM 48 What does this print? System.out.printf(%.5f\n, (double)3); DEFINITION 48
TERM 49 What does this print? System.out.printf(%.5f\n, 3); DEFINITION 49 Illegal Formatting Exception TERM 50 Close the Scanner called reader. DEFINITION 50 reader.close();
How do you store and check if the predefined String variables s1 and s2 are equal into the b? b = s1.equals(s2); TERM 52 Scanner keys to read and store the first word into String s. DEFINITION 52 s = keys.next(); TERM 53 Scanner keys to read and store following line into String s. DEFINITION 53 s = keys.nextLine(); TERM 54 What does this print - String s = Cool bro; System.out.println (s.substring(2, 6)); DEFINITION 54 ol b TERM 55 for (int l = 0; l > 0; l++) System.out.println(l); prints what? DEFINITION 55 nothing
Print the length of the array (with a new line). System.out.println(stringArray.length); TERM 62 Declare and allocate a 4x7 2D char array called letters. DEFINITION 62 char [][] letters = new char [4][7]; TERM 63 Print each element of the predefined 2D byte array called b DEFINITION 63 for (int i = 0; i < b.length; i++){ for (int j = 0; j < b[i].length; j++) {}}System.out.print(b[i][j]); TERM 64 Declare and assign a 3x3 2D double array, called doubleTable, assigning vales of 2.0. DEFINITION 64 double [] [] doubleTable = new double [3][3];for (int i = 0; i < doubleTable.length; i++) for (int j = 0; j < doubleTable[i].length; j++)doubleTable[i][j] = 2.0;ORdouble [] [] doubleTable = {{2.0, 2.0, 2.0}, {2.0, 2.0, 2.0}, {2.0, 2.0, 2.0}}; TERM 65 When do you need to use the keyword this? DEFINITION 65 When you are accessing class variables that have the same name as a local variable.