Advertisements
Advertisements
Question
Observe the following code. It may contain Syntax, Logical or runtime errors. Execute it in Java and identify the error, if any. Rewrite the code without the error. Also write the aim of the code.
int fnTotalDigits(int n)
{
int td=0;
while(n>0)
{
n=n/10;
td++;
}
return td;
System.out.print("total digits=" + td);
}
Code Writing
Advertisements
Solution
int fnTotalDigits(int n)
{
int td=0;
while(n>0)
{
n=n/10;
td++;
}
System.out.print("total digits=" + td);
return td;
}
shaalaa.com
Is there an error in this question or solution?
Chapter 3: User-Defined Methods - Exercises [Page 93]
