CSCI 202 Homeworks 2 & 7

Rules of submission

This assignment must be submitted either in class on Thursday, 21 March, or uploaded to the Moodle submission page for Homeworks 2 & 7 by 6:00 PM on Thursday, 21 March.

Homework 2 revisted

The Homework 2 asked you to indicate the tokens in a Java class. This didn&nbsdp;t work out well, so we re going to try it again.

Just to make it clear what is desire, the tokens on the following line of Java code
    String s = "hi " + (int) /* hi */ (2.5 * ( k +j)) ;
are the following:

Having seen this example, redo the Homework 2 example, repeated below. I strongly suggest you circle the tokens. Outlining them just doesn t work. The individual tokens all run together.

package edu.unca.cs.csci202.jan222012;

  // A Java program of sorts

public class Example1 {

    public static void /* of use */ main(String[] args) {
        int x = (int)(3.14 / (5 << 2)) ;
        for (int i=x; i<202; ++i) {
            System.out.println("This is line " + i) ;
        }
        System.out.println("abcd" == "ab" + "cd") ;
        System.out.println("abcd".equals("ab".concat("cd"))) ;
    }
}

Homework 7

In this homework, you are to show all the subexpressions of a Java expression. You should follow the expression structure discussed in the Quick look at legal Java expressions lecture.

As an example, let’s try out the following Java expression:
    x = (int)(3.14 / (5 << 2))
Its subexpressions are shown below. In your answer, it’s not necessary to short the “sort” of the expresion.

ExpressionSort
x = (int) ( 3.14 / ( 5 << 2 ) ) assignment
x identifier
(int) ( 3.14 / ( 5 << 2 ) ) cast
( 3.14 / ( 5 << 2 ) ) parenthesized expression
3.14 / ( 5 << 2 ) multipicative
3.14 literal
( 5 << 2 ) parenthesized expression
5 << 2 shift
5 literal
2 literal

Inspired by this example, find the subexpressions of the following. You can do this by circling the subexpressions, but you will need to used a large font (or handwriting) to make it readable.

degree = ( (int) (r * 180 / Math.PI ) + 90) % 360