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

Question 2(iv)

3 marks

Computer ScienceISC 2026 Computer Science Paper 1Fill inImplementation of algorithms to solve problems

Fill in the blanks marked ?1?, ?2? ... so that the code works.

The following function isTech( ) is a part of some class which is used to check if a given number…

The following function isTech( ) is a part of some class which is used to check if a given number is a Tech number or not. 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. A number is Tech number if the count of digits is even and the square of the sum of its two equal halves is equal to the number itself. Example: $2025 = 20 + 25 = (45)^2 = 2025$
boolean isTech(int n)
{
    String s = String.valueOf(n);
    int len = ?1?;
    if (len % 2 != 0)
        return ?2?;
    int first = Integer.parseInt(s.substring(0, len / 2));
    int second = Integer.parseInt(s.substring(len / 2));
    int sum = first + second;
    return ?3? == n;
}

Answer

Answer

Blanks: s.length(); false; sum * sum

?1? = s.length() ?2? = false ?3? = sum * sum