![]() |
![]() |
|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
We will spend most of today finishing up the ebay lab from Tuesday (including the three-tiered price structure for items over $1000.)
First though, we'll take ten minutes to look at / for doubles vs. / for ints vs. % (remainder).
Remember that /, if given two integers, returns the quotient. The remainder can be obtained by % (pronounced “mod” or “modulo” in addition to “remainder”). Predict the result of each expression to your partner, then try them out:
int n = 1234; // Or however much money was dumped in, in cents. n // Type this in code pad, just to check its value. int quartersBack; // How many quarters we'll return. quartersBack = n / 25 ; int stillDue25; // How much money we still owe back, after quarters. stillDue25 = n % 25 ; quartersBack // Type this in code pad, just to check its value. stillDue25 // Type this in code pad, just to check its value. int dimesBack; dimesBack = stillDue25 / 10 stillDue10 = stillDue25 % 10 int nickelsBack; nickelsBack = stillDue10 / 5 stillDue5 = stillDue10 % 5 |
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
| ©2008, Ian Barland, Radford University Last modified 2008.Feb.06 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |