Forums Register Login

Comparison of floats

+Pie Number of slices to send: Send
Hiya guys, new here. Trying to put together my own little program, and I've pretty much done it all, just have one or two things to throw together. Basically I need to compare three numbers from a file, to a scanner input file. I've done the inFile fine and got the numbers in. What I need to do is compare these floats with the scanner input number, and find the one which is closest to the scanner.in number.
So I just need to find the one which is closest to the user input.
Not sure how to approach this, really. Any suggestions?
+Pie Number of slices to send: Send
Welcome to the Ranch.

First think about the logic to do this, without thinking about how to write it down in code.

So, you have three numbers A, B and C, and you want to find out which of the numbers B and C is closest to A. How would you do that? (Explain it to yourself in plain English, not in Java code).
Hint: Think about the difference between A and B, and A and C. When you know the differences, how can you find out which one is closest to A?

Once you understand the logic, you can think about how to write that down in Java code.
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 335 times.
Similar Threads
Can someone send me any kind of examples; trying to learn java
cannot find symbol compile error
Netbeans and Scanner.in
Input values to an ArrayList
Linear comparison algorithm
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:10:49.