← all problems

roundPositive 🌶️🌶️

Write a method that takes one positive double parameter, value, and returns it rounded to the nearest int: round up when the decimal part is 0.5 or higher, and round down otherwise. For example, roundPositive(4.5) should return 5, and roundPositive(4.49) should return 4. You can assume value is always positive and you don't need to handle negative numbers.

AP Computer Science A students: Although you can find a method inside Math that can handle rounding for you and for real projects you absolutely should use it, the exam expects you to understand how to produce an expression involving a typecast operation that does this.