हिंदी

The following function is Tech() 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 - Computer Science (Theory)

Advertisements
Advertisements

प्रश्न

The following function is Tech() 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?:

  intfirst = Integer.parselnt(s.substring(0, len/2));

  int second = Integer.parseInt(s.substring(len/2));

  int sum =first + second;

  return ?3? == n;

}

What are the expressions or statements at?1?, ?2? and ?3?

दीर्घउत्तर
Advertisements

उत्तर

To make the isTech() function work correctly based on the logic of a Tech number, the placeholders should be replaced as follows:

  • ?1? : s.length()
    This calculates the total number of digits in the number by getting the length of the string s.
  • ?2? : false
    A Tech number must have an even count of digits. If the length is odd (len % 2 != 0), it immediately fails the condition, so the function returns false.
  • ?3? : sum * sum (or Math.pow(sum, 2))
    The final step checks if the square of the sum of the two halves is equal to the original number n.
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×