Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ANSWER KEY TO THE 2017 SPRING CS401 FINAL EXAM

#1)       I want to run a program Q1.java to print the sum of the numbers entered on the command line:

like below

C:\> java Q1 12 34 32 54 56 76 89

Here’s the code for Q1.java.  Select an answer below that describes the

outcome.

 

A        Wont even compile. Will produce compilation errors from the javac

command.

#2)       If I execute a program Q2.java at the command line like this:

C:\> java Q2

What will be true about the args array at the moment the program starts to execute?

B         it will not be null but will be of length 0

#3)       Here is a java file that compiles cleanly with no errors:

 

What will happen if I execute it from the command line like this:

C:\> java Q3

B         it will not execute

-OR-  either answer, B or C is acceptable

C         it will start to execute but immediately give a fatal error

#4)       In java, which of the following statements is true:

A         Every executable program is a class

#5)       What is the output of the following program?

 

A        0 2 4 6 8

#6)       Which of the following statements is true about Q5 above?

B         line 9 is just handing off a copy of arr’s reference to the fillArr method

#7)       What is the output of the following program?

 

A        0 2 4 6 8

#8)       Which of the following statement s is true about Q7 above?

B         the copyArr() method  is just returning the reference value in  arr1

#9)        Which of the following containers most closely follows the array discipline ?

A        ArrayList

#10)     Which container does the following diagram most closely illustrate?

 

C         HashSet

#11)     Which container does the following diagram most closely illustrate?

 

D        TreeSet

#12)     Which container does the following diagram most closely illustrate?

 

E         TreeMap

#13)     Why is the output of the following program?

 

C         finals hate i really

#14)     Recall the Fraction class you wrote. Suppose that you were to remove the setNumer() and           setDenom() methods from your class definition.  What would then be true about your modified Fraction class?

A        it would be an immutable class

#15)     Suppose you have a very large file of Strings and you want to find out if the file contains any dupes. What would be the simplest, most efficient (fastest) container to read those Strings into, to  simply determine yes/no, there is or is not, a duplicate in that file?

C         HashSet

#16)     Why is the output of the following program?

 

E         they come out in no guaranteed order

#17)     Recall the Boggle program. Which of the following statements is true?

B         in order to solve large boards faster you must use an algorithm that

avoids forming words that will never be found in the dictionary

#18)     Recall the Jumbles program you wrote twice (once as a project then as a lab).

Which of the following statements is true about that program?

B         a HashMap is a very fast and very simple mechanism to match up a

jumbles word with equivalent dictionary words

#19)     Comparing the Boggle program and the Swamp program, which of the following statements is

true?

D        A,B and C are all true

#20)     Which of the following are necessary components of a recursive solution?

D        all of the above

#21)     You are asked to fill in the code for method that takes an int and returns true or false if the int

is/is not a random number:   boolean isRandom( int r ); // returns true if r is a random