Say I have three numbers A, B and C. How would I check if B lies between A and C without assuming that A < C or A > C?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Say I have three numbers A, B and C. How would I check if B lies between A and C without assuming that A < C or A > C?
How would you do this without a computer? How do you do it in your head?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
lol that's what im trying to figure out....What I've thought of so far was thinking of it as a distance or absolute value....Or maybe even finding the median between both numbers and going from there. But I'm still not sure what I should do...
A big part of figuring out an algorithm is taking things that we do in our heads without really thinking about and breaking them up into smaller individual steps. Pretend you have a really dumb friend who has no idea how to figure out whether a number is in between two other numbers. Write out directions for him that he could follow to accomplish the task. When you have that written out, you should have an algorithm that should be pretty easily translated into code.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
hint: compute the lower/upper bounds
hint: you said you can't assume that a < c or a > c, and you're correct. But you CAN figure it out, and then work form there.
Let's say;
What willint a=5; int b=4;
results?int c=a/b;
System.out.println(b > (a < c ? a : c) && b < (a > c ? a : c));
Improving the world one idiot at a time!
I took it to mean that A could be less than C or A could be greater than C. Either could be true so you would have to test both cases.
Improving the world one idiot at a time!