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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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