Assignment 2, due Jan 27
Part of
the homework for CS:2820, Spring 2017
|
On every assignment, write your name and section number. Write your name as it appears on your university ID card! Use the section number as it appears in your current registration! We will not do detective work to figure out who did what. Homework is due on paper at the start of your discussion section. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God"). Never push homework under someone's door!
a) What is the Boolean expresson that determines whether or not this program executes a for loop? (Hint: Read the code) (0.5 points)
b) The for loop in this program introduces a nee variable called s. Using only the information you can see when you read the code, with no hint of the context in which the code is executed, what can you say about the value of s on the first iteration of the loop? (0.5 points)
A simple programming problem: Translate the informal function definition given in Homework 1 into a recursive Java method, and then embed that method in a well formatted program that calls the method to print the successive values. Here is an example of what the first few lines of your output should look like:
f(0)=0 f(1)=1 f(2)=2 f(3)=2 f(4)=3
Handwritten code is sufficient; you are not required to run your program, but you can be more assured that it works if you test your program.
Note that a complete, cleanly formatted solution requires fewer than 20 lines of code -- Just this once, don't bother with comments so long as your name and section number are on the page. You will be graded on formatting and code correctness! Any java program can legally be written as one line of code, but it's not very readable if you do that. (1 point)
A question: The latter are Javadoc comments. When the javadoc command is applied to a program containing these comments, what does it produce as output? (Hint: The assigned reading in the textbook answers this question.)