Advertisements
Advertisements
प्रश्न
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.
- What will the function workOut(220) return? [2]
- What is the function workOut() performing apart from recursion? [1]
लघु उत्तर
Advertisements
उत्तर
(a) Dry run:
220 ÷ 16 → Quotient = 13, Remainder = 12 → C
13 ÷ 16 → Quotient = 0, Remainder = 13 → D
Function calls:
workOut(220) = workOut(13) + 'C'
workOut(13) = workOut(0) + 'D'
workOut(0) = ""
workOut(13) = "D"
workOut(220) = "D" + "C"
workOut(220) = "DC"
(b) The function converts a decimal number into its hexadecimal equivalent using recursion.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Official Board Paper
