Assignment 2, due Jan 27

Part of the homework for CS:2820, Spring 2017
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

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!

  1. Background: Get a copy of the code for mp1.java (see the assignment for Machine Problem 1).

    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)

  2. Background: Look at the recursive function given on Homework 1, problem 1.

    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)

  3. Background: Java supports 3 kinds of comments:
    — line-end comments //like this
    — in-line comments /* like this */ within program text,
    — and a special class of comments /** like this */

    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.)