Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Advertisements
प्रश्न
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021
Output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4]
Example2:
Input: 125
Output: Not an SUPERSPY number [1+2+5 is not equal to 3]
संक्षेप में उत्तर
Advertisements
उत्तर
class superspy
{
int n;
superspy(int x)
{
n=x
}
boolean superspy()
{
int d,s=0,c=0;
while(n>0)
{
d=n%10;
s=s+d;
c++;
n=n/10;
}
if(s==c)
return true;
else
return false;
}
}
shaalaa.com
Introduction of Iterative Constructs in Java
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
