Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 2(iii)(b)

1 mark

Computer ScienceISC 2026 Computer Science Paper 1Short answerRecursion

What is the output of the following code?

What is the function workOut( ) performing apart from recursion?

Show the code
The following function workOut( ) is a part of some class. Assume 'n' is a positive integer.
String workOut (int n)
{
    if (n == 0)
        return "";
    int rem = n % 16;
    char cr = (rem < 10) ? (char)(rem + '0') : (char)(rem - 10 + 'A');
    return workOut (n / 16) + cr;
}
Open in the Recursion visualiser

Answer

Answer

The function converts a positive decimal integer into its equivalent hexadecimal representation (as a String).