Flogging a dead horse - reading a number
Kenneth Fogel
kfogel at dawsoncollege.qc.ca
Sun Jan 19 17:55:34 UTC 2025
Hi,
I have started a new course this past week, a first level Java course. Once we get past "Hello Moose" (in Canada we prefer this to Hello World) I present a simple program that calculates loan payments. Then I present an interactive version where I am forced to write:
var loan = Double.parseDouble(readln("Loan: "));
var interest = Double.parseDouble(readln("Interest: "));
var term = Double.parseDouble(readln("Term: "));
Its all going well until I must describe what Double.parseDouble is.
I do not need a read for each numeric type. A read for doubles is all I think is necessary and then I could write:
var loan = (readNum("Loan: ")); // loan is a double
or if I need an integer:
var numberOfCarrots = (int)readNum("How many carrots do you need? ");
Heck, if I were greedy, I'd ask that if you cast a readln this results in numeric input:
var loan = (double) readln("Loan: ")); // Just like Python
But I'm not that greedy, today.
Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250119/f8f9dd6d/attachment-0001.htm>
More information about the amber-dev
mailing list