CS 1401 Homework #2

Date Assigned: Monday, September 19, 2005 or Tuesday, September 20, 2005

Due Date: Wednesday, September 21, 2005, or Thursday, September 22, 2005, before the beginning of your lecture section.

Goal: the goal of this assignment is to learn how to deal with numbers in Java.


1. What will be the result of the following expressions:

(a) 4/2/8

(b) 4.0/2.0/8.0

(c) a++ (if a was originally 10)

(d) --a (if a was originally 10)

(e) 4%2%8

(f) -4.0%-2.0*-8.0

2. Let b be a variable of type int. Use type casting to assign b's value to the following variables:

(a) shortB of type short

(b) doubleB of type double

Explain in which of these two cases we can use type conversion instead of type casting. If type conversion is possible, what is the advantage of type casting?