Posts

Showing posts with the label cs3401 alan shaw

CS3401 Practice Quiz 2 Part 2

Image
Introduction to Java Programming Introduction to Java Programming, Ninth Edition, Y. Daniel Liang Chapter 10 Thinking in Objects Please send suggestions and errata to Dr. Liang at y.daniel.liang@gmail.com . Indicate which book and edition you are using. Thanks! Section 10.2 Immutable Objects and Classes 10.1   Which of the following statements are true about an immutable object? A. The contents of an immutable object cannot be modified. B. All properties of an immutable object must be private. C. All properties of an immutable object must be of primitive types. D. An object type property in an immutable object must also be immutable. E. An immutable object contains no mutator methods. Your answer is correct Section 10.3 Scope of Variables 10.2   What is the printout for the first statement in the main method? public class Foo {   static int i = 0;   static int j = 0;  ...

CS3401 Quiz 1 - No answers yet will update

Image
Question 1  (5 points)   How many times is the following factorial method invoked for complicatedSum(6)? public int complicatedSum(int n) {     if (n <= 3)         return n;     else if (n % 3 == 0)         return n * 3 + complicatedSum(n-1);     else if (n % 3 == 2)         return n * 2 + complicatedSum(n-1);     else         return n + complicatedSum(n-1); } Question 1 options: 6 5 4 3 Save Question 2  (5 points)   What does recursiveString("abcd") return if that method is defined by the following?   public String recursiveString(String str) {       if (str.length() < 2)       ...