PRASHNIKAप्रश्निका
‹ Back to the paper

What is the output of the following code?

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

Computer Science20261 markShort answer
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;
}

Answer

Answer

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

From ISC 2026 Computer Science Paper 1, question 2(iii)(b).