• 12
• Locked
Here's the sixth task in the "Integer Type Conversions" series. What are we shooting for here? We want you to master these techniques so you don't have to relearn them. This time our task has too many cast operators. Superfluous conversions have crept in. Find and remove them to get the required answer.
You can't complete this task, because you're not signed in.
Ajani
Level 16 , Jacksonville, United States
29 January, 23:11
So i feel we miss so much in this chapter when they just gloss over these type limits. You need to understand the basics of them to be able to change them effectively, which i do not. According to Rishi earlier in this chapter. a short can only store value ranges of -32,767 to its positive opposite 32,767. So when you do an explicit cast on the int I dont understand why its result is 18,928 vs the max it could be of 32,767.
Michael
Level 10 , Dresden, Germany
30 December 2021, 10:33
While the tasks in this chapter are mathematically clever, they miss the point of learning the concept of typecasting. So much for Java to be an intuitive and simple programming language ...
14 February, 22:38
Here's how I solved this intuitively. I can' share the test class I created outing all the values as it runs, and testing out changes ... but here is the gist in case it could help others. Basically just start working with the values. int i = (short) 150000; // <-- casting 150000 to short will truncate the value float f = (short) 0.50f; // <-- casting .50f to short will be < 1, so zero what if we did not truncate f using short? We retain the .5 which gets us a non-fractional result (the given result was fractional by .5). what if we did not truncate i using short? we get a numerator much larger, which gets us a larger result.
Anonymous #10775689
Level 14 , United Kingdom
3 August 2021, 12:14
``char c = (short) 'd';``
It's the letter 'd', but what about it's value as an ASCII character? That's what is used when we divide by 'd'. ASCII - Binary Character Table