‹ Back to the paper
Question 2(iv)
3 marks
Computer ScienceISC 2025 Specimen Computer Science Paper 1Case basedImplementation of algorithms to solve problems
Fill in the blanks marked ?1?, ?2? ... so that the code works.
The following is a function of class Armstrong. This recursive function calculates and returns the…
The following is a function of class Armstrong. This recursive function calculates and returns the sum of the cubes of all the digits of num, where num is an integer data member of the class Armstrong.
[A number is said to be Armstrong if the sum of the cubes of all its digits is equal to the original number].
There are some places in the code marked by ?1?, ?2?,?3? which may be replaced by a statement/expression so, that the function works properly.
public int sumOfPowers(int num)
{
if (num == 0)
return ?1?;
int digit = ?2?;
return (int) Math.pow(digit, 3) + ?3?;
} (a)[1]
What is the expression or statement at ?1?
(b)[1]
What is the expression or statement at ?2?
(c)[1]
What is the expression or statement at ?3?
Answer
Answer (a)
Official answer keyBlanks: 0
?1? = 0
Answer (b)
Official answer keyBlanks: num % 10
?2? = num % 10
Answer (c)
Official answer keyBlanks: sumOfPowers(num / 10)
?3? = sumOfPowers(num / 10)