posted 7 months ago
So I was inspired by this little math problem I received today from Brilliant.com
A = 9^9 / 10^9
B = 9^10 / 10^10
Which is bigger?
So, like any good novice Java developer, I created the following Java class to solve it:
I know that compreTo is supposed to give me a 1, 0, or a 1. Which essentially means less than, equal, or greater than..... but how to print this out? Currently, all that shows in my console view is this:
a is: 0.387420489
b is: 0.3486784401
Also, is there a better way to compare "a" and "b"?
A = 9^9 / 10^9
B = 9^10 / 10^10
Which is bigger?
So, like any good novice Java developer, I created the following Java class to solve it:
I know that compreTo is supposed to give me a 1, 0, or a 1. Which essentially means less than, equal, or greater than..... but how to print this out? Currently, all that shows in my console view is this:
a is: 0.387420489
b is: 0.3486784401
Also, is there a better way to compare "a" and "b"?
Mark Richardson
Ranch Hand
Posts: 134
2
posted 7 months ago
This is not true. This method can return any int.
you should check whether the value is zero, or is positive, or is negative.
You shouldn't check whether the value is 1 (or 1).
Mark Richardson wrote:I know that compreTo is supposed to give me a 1, 0, or a 1.
This is not true. This method can return any int.
you should check whether the value is zero, or is positive, or is negative.
You shouldn't check whether the value is 1 (or 1).
posted 7 months ago
If X(p) = a^p / b^p, what is the relation between X(n) and X(n+1)? Can you now devise an easier way to compare the two? (if still needed).
Mark Richardson wrote:So, like any good novice Java developer, I created the following Java class to solve it:
(...)
Also, is there a better way to compare "a" and "b"?
If X(p) = a^p / b^p, what is the relation between X(n) and X(n+1)? Can you now devise an easier way to compare the two? (if still needed).
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
