CSE 131 / 501N (Summer 2014)

Recitation Questions

When asked to write a method, you must consider appropriate names and types for your solution. Unless otherwise specified, you must come up with the names and types of your parameters and return values, so consider the following:
  1. Open up any code we have given you or you have written. In that code, identify for each method the following:
  2. Problem 2.1.12 on page 210
  3. Problem 2.1.13 on page 210
  4. Problem 2.1.2 on page 209
  5. Write a method isFirstLessThan that takes in three double values, and returns true if and only if the first value is less than the sum of the other two.
  6. Now write a method areEachLessThan that returns true if and only if each of its three parameter's values is less than the sum of the other two. You must use the method isFirstLessThan in your solution. Your solution should be fairly short.
  7. Write a method cube that returns the cube of its integer parameter's value.
  8. Write a method isCube(int n, int m) that returns true if and only if m=n3.
  9. What role does a stack play in calling methods and finding their return values? (Review the lecture slides if you are not sure.)
  10. Suppose the method int sum(int a, int b) is about to be called on the values 5 and 7.
  11. What does void mean as a method's return type?
  12. Why does the following code cause an error in Java?
    public static int absValue(int value) {
       if (value >= 0) {
          return value;
       }
       if (value <  0) {
          return - value;
       }
    }
    
  13. How can you fix the above error?