Programming and Computer Science in Java:

More Simple Java Programs

See Course Home Page.

**Due
Date: Fri, Feb 7, 2003**

First, read Chapter 2 from Downey. Study this for a ** quiz Friday.**
Then, do the following problems.

Write the following 3 Java programs -- without a computer:

1. Find the sum of the numbers from “lo” to “hi”.

2. Find the sum of the squares from “lo” to “hi”.

3. Find the “Manhattan” distance from (x1,y1) to (x2,y2). As we
discussed, this is the distance one must walk in Manhattan from an intersection
at (x1,y1) to an intersection at (x2,y2). As there are buildings in your
way, you must walk straight down the x axis, and then straight down the y
axis. The answer would simply be the sum of (x2 - x1) and (y2 - y1),
except that x2 might be smaller than x1 (and, similarly, y2 might be smaller
than y1). To address this problem, you can make use the functions min(a,b)
and max(a,b) or, if you prefer, the function abs(x).

Good luck!

DK

See Course Home Page.