Write a recursive function called sumdigits

Assignment Help Computer Engineering
Reference no: EM132076131

Need help with java program

Directions

Write a recursive function called sumDigits with the following signature:

public static long sumDigits(long n)

that computes the sum of the digits in a number repeatedly, until the sum is a single digit.

For example, if we call sumDigits(123456), the following would result:

sumDigits(123456) => 1+2+3+4+5+6 => 21 => 2+1 => 3

so the final answer would be 3.

You must meaningfully use recursion for this lab in order to receive any credit.

Hint: For this problem it might be useful to convert back and forth between longs and strings. This can be done using the Long.parseLong method and the Long.toString method.

Reference no: EM132076131

Questions Cloud

Critical points of f as either saddle : Find and classify all critical points of f as either saddle, local min or local max.
Creates an array capable of holding four shape objects : Create two subclasses of Shape: Circle and Square. Then, you should write a driver program with a main method .
Using recursion determine the number of tribble for any hour : Write a JAVA program that uses recursion to determine the number of tribble for any hour.
Write three overloaded methods that calculate averages : The first method takes two integer parameters, the second takes three integer parameters, and the third takes four integer parameters.
Write a recursive function called sumdigits : Write a recursive function called sumDigits with the following signature: public static long sumDigits(long n).
Create a package named reading_with_exceptions : Create a package named "reading_with_exceptions". Write a class named: Reading_With_Exceptions with the following method.
Find the work done hoisting : Find the work done hoisting a 1,500 pound generator 50 feet straight up into the air. Assume the force of gravity is acting straight downwards
What is the instantaneous rate of change : What is the instantaneous rate of change of the remaining amount of medication after 1 hour?
Calculate new dimensions for the textdraw panel : Calculate and save the difference between the two in both the height and width dimensions.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Describe concept of interaction design

One of your colleagues who is not familiar with Interaction Design. Explain and describe concept of Interaction design to him or her. Please add appropriate details and examples with applicable references in APA style.

  Write a program that plays tic-tac-toe

Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3 grid as in the photo at right.

  How do you use tar to add two files

How do you use tar to add two files, foo.html and bar.html, to an archive, archive.tar, and then compress the archive?

  Suppose password, email, name and address, max score

the password should not be same as employee ID and must contain 4-6 characters

  Explain the term low-order memory interleaving

Explain the terms Low-order memory interleaving, physical address cache versus virtual address cache and atomic versus non-atomic memory accesses.

  Derive the micro operation sequences needed for operations

For the stack-based ALU shown in Figure, derive the micro operation sequences needed for the following operations.

  Determining different sales transactions

By using example of the retail clothing store in a mall, state the relevant data flows, data stores, processes, and the sources/sinks. Find out the different sales transactions.

  How to write a complete interactive java gui program

Write down a complete interactive Java GUI program that requests two numbers from the user. The first number is the row dimension and second number is the column dimension

  How the actor-critic control method could be combined

Describe how the actor-critic control method could be combined with gradient-descent function approximation.

  Perform a fit-gap analysis of the scenario

Perform a fit-gap analysis of this scenario considering organizational/social changes as well as IT changes.

  Summarize the scenario you would be dealing with as the

write 400-600 words that respond to the following questions with your thoughts ideas and comments. this will be the

  What is jitter and why is it a digital signal problem

What is jitter and why is it a digital signal problem? Which types of noise introduced in this chapter are continuous, and which are noncontiguous?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd