CS 1401 Homework #4

Date Assigned: Tuesday, February 8, 2005

Due Date: Thursday, February 10, 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) 2/1/4

(b) 2.0/1.0/4.0

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

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

(e) 2%3%4

(f) -2.0%-0.9*-4.0

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

(a) longA of type long

(b) doubleA of type double

(c) stringA of type string

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