answersLogoWhite

0

Add the last digit plus the sum of all the previous digits. The base case is that if your integer only has a single digit, just return the value of this digit.

You can extract the last digit by taking the remainder of a division by 10 (number % 10), and the remaining digits by doing an integer division by 10.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Can a recursive method be void, or does it always need to return a value?

Yes, a recursive method can be void, meaning it does not need to return a value.


What is a recursive research method?

an answer that refers to itself.


Write a recursive method to compute the number of digits in a positive integer?

Such a method could be: public int NumberOfDigits(int num) { num = num/10; if( num == 0) return 1; return ( 1+NumberOfDigits(num) ); }


What is the computational complexity of the recursive factorial method?

The computational complexity of the recursive factorial method is O(n), where n is the input number for which the factorial is being calculated.


Differences between declaring a method and calling a method?

Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).


What is recursive methods?

A recursive method is a method that can invoke itself. The classical example is N factorial...int nfact (int N) {if (N == 2) return N else return N * nfact (N - 1);}The example suffers from truncation issues, because N Factorial gets very large, very quickly, with relatively small values of N, and ordinary integers do not support that. The answer, however, is sufficient for the question of "what is a recursive method?"


Biggest of three nos using recursive method?

biggest3 (a,b,c) = biggest2 (a, biggest2 (b,c))


What is recursive algorithm?

Algorithm can be defined as an interpretable, finite set of instructions for dealing with contigencies and accompanying task that has recognizable end-points for given inputs. It is a tool for solving a well computational problem. A recursive algorithm is one which calls itself.


What is abstract methods?

Simply, Abstract method is a method that is declared without or containing no implementation. It has a method signature


How do you check whether the given number is Armstrong or not?

First, review the definition of an Armstrong, or narcissistic, number:"...is a number that is the sum of its own digits each raised to the power of the number of digits."So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:String numberAsString = "" + number;Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.Another way is to get one digit at a time, starting from the right, using the "%" operator.For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.First, review the definition of an Armstrong, or narcissistic, number:"...is a number that is the sum of its own digits each raised to the power of the number of digits."So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:String numberAsString = "" + number;Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.Another way is to get one digit at a time, starting from the right, using the "%" operator.For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.First, review the definition of an Armstrong, or narcissistic, number:"...is a number that is the sum of its own digits each raised to the power of the number of digits."So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:String numberAsString = "" + number;Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.Another way is to get one digit at a time, starting from the right, using the "%" operator.For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.First, review the definition of an Armstrong, or narcissistic, number:"...is a number that is the sum of its own digits each raised to the power of the number of digits."So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:String numberAsString = "" + number;Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.Another way is to get one digit at a time, starting from the right, using the "%" operator.For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.


Which of the following is not a retrospective-type accounting change?

Sum-of-the-years'-digits method to the straight-line method


What does stack overflow at line 104 mean How can you remove it?

Go to line 104, look carefully (ask someone else if you could not spot it). You either have a method or property name referenced within the same method or property. Or, you may have A calls B, B calls C, C calls A, a circular recursive chain... It is common to have stack overflow with recursive call (unintentionally of course)