java - Missing return statement due to If condition -


so have following function:

int digitsum(int n){     int s = n;     if(n < 10)          return s;          while(s > 0){         n = s + n % 10;         s = n / 10;     }     digitsum(n); } 

i want take number , sum of digits , want keep doing until end single digit number. can understand here, if statement causing error during compilation, says missing return statement , highlights last } .

can me this?

in non-void function , every function call must trace return statement , java says

every execution path in function must lead return statement

so add return digitsum(n);

according rule in java , if condition if(n < 10) false there no further return statement exists either there should default return statement or there should other return statement in conditional else case.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -