CS 1401 Homework #1

Date Assigned: Monday, September 12 or Tuesday, September 13, 2005

Due Date: Wednesday, September 14, or, correspondingly, Thursday, September 15, 2005, before the beginning of your lecture section.

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

Assignment:
Write, on a sheet of paper with your name on it, a piece of code that asks the user for a height in inches and returns the corresponding height in centimeters. The corresponding formula is

height_in_cm = 2.54 * height_in_inches
Take into account that the height is not always an integer.

Trace your code on an example of 100 inches, which should result in 254 cm.

What will happen if instead of 2.54 you write (254/100)? Will the result still be correct?

For extra credit: write a piece of code that transforms from centimeters to inches; hint: divide by 2.54.