aeonsky Posted October 1, 2008 Share Posted October 1, 2008 This was on one of my quizzes... What is the value of 17*(32654/17) + 32654%17 It turns out to be == 32654, for the love of God, I have no idea why. I thought >>> 32654 + 14 = 32668 Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/126547-very-easy-java-math-question/ Share on other sites More sharing options...
DarkWater Posted October 1, 2008 Share Posted October 1, 2008 17 * (32654/17) is 32640 (probably due to integer rounding). Quote Link to comment https://forums.phpfreaks.com/topic/126547-very-easy-java-math-question/#findComment-654729 Share on other sites More sharing options...
corbin Posted October 2, 2008 Share Posted October 2, 2008 Integer rounding is a pain. I wonder how modular arithmetic works on computers.... I would think it would simply be: b*(a/b) + a%17 Would turn into: b*ceil(a/b) + b(a/b - ceil(a/b)) But I have no idea since if done separately as integers in Java, 17(32654/17) is, like DW said, 32640, and oddly enough, 32654%17 is 5. Quote Link to comment https://forums.phpfreaks.com/topic/126547-very-easy-java-math-question/#findComment-655319 Share on other sites More sharing options...
aeonsky Posted October 2, 2008 Author Share Posted October 2, 2008 LMAO, totally forgot that Java rounds numbers if it is an integer. It does, indeed equal to 32654. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/126547-very-easy-java-math-question/#findComment-655404 Share on other sites More sharing options...
corbin Posted October 2, 2008 Share Posted October 2, 2008 I think C++/C do too. Not a Java thing. Quote Link to comment https://forums.phpfreaks.com/topic/126547-very-easy-java-math-question/#findComment-655496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.