The following function workOut( ) is a part of some class. Assume 'n' is a positive integer…
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 the questions given below with the dry run / working.(a)[2.0]
What will the function workOut(220) return?
(b)[1.0]
What is the function workOut( ) performing apart from recursion?
Answer
Answer (a)
AIWritten by AI (antigravity) - it can contain mistakes.
Dry run of workOut(220):
Call 1: workOut(220) -> rem = 220 % 16 = 12 -> cr = (char)(12 - 10 + 'A') = 'C'; calls workOut(13) + 'C'
Call 2: workOut(13) -> rem = 13 % 16 = 13 -> cr = (char)(13 - 10 + 'A') = 'D'; calls workOut(0) + 'D'
Call 3: workOut(0) returns ""
Unwinding:
Call 2 returns "" + 'D' = "D"
Call 1 returns "D" + 'C' = "DC"
Return value: "DC"
Answer (b)
AIWritten by AI (antigravity) - it can contain mistakes.
The function converts a positive decimal integer into its equivalent hexadecimal representation (as a String).
From ISC 2026 Computer Science Paper 1, question 2(iii).