i was doing the hit and trial and what i though is why we really need to abs method when we need to get the correct number closest to 10 even if both numbers are -ve.
Example: if we take 2 number
-8, -13
then abs method will be changing them to +ve number and when we are going to compare the +ve number it is not going to give us the correct value. so i made a change in the abs method which make the method itself irrelevant by setting the first if clause as +a instead of -a.
when i ran my program it worked fine and ticked everything as green.
but here the trick is how you are going to still identify the number closest to 10 and when i compare my solution with the actual solution, it gives me more confidence that how each exercise if going to help you further to improve yourself.
why we need the abs method
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
hidden #10757948
22 June 2021, 11:05
abs() method returns the absolute (Positive) value of a int value. This method gives the absolute value of the argument. The argument can be int, double, long and float. That's all! It's so simple. For more You should upload your code, PrtSc or something... make comments what's wrong in code also....Enjoy! Cheers!!!
0
Thomas
19 June 2021, 11:42
It's always the best to post your code. For now I can just tell you that the task probably won't validate if you change code that you're not supposed to change.
+1