Write a method that computes the sum of the digits in an integer. Use the following method
Question:
Write a method that computes the sum of the digits in an integer. Use the following method header:
public static int sumDigits(long n)
For example, sumDigits(234) returns 9 (2 + 3 + 4).
To remove 4 from 234, use 234 / 10 (= 23). Use a loop to repeatedly extract and remove the digit until all the digits are extracted. Write a test program that prompts the user to enter an integer and displays the sum of all its digits.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 53% (15 reviews)
Sample output Enter an integer 12345 Sum of the digits of integer 12345 is 15 M...View the full answer
Answered By
Nyron Beeput
I am an active educator and professional tutor with substantial experience in Biology and General Science. The past two years I have been tutoring online intensively with high school and college students. I have been teaching for four years and this experience has helped me to hone skills such as patience, dedication and flexibility. I work at the pace of my students and ensure that they understand.
My method of using real life examples that my students can relate to has helped them grasp concepts more readily. I also help students learn how to apply their knowledge and they appreciate that very much.
4.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Write a method that computes the commission, using the scheme in Programming Exercise 5.39 . The header of the method is as follows:public static double?computeCommission(double?salesAmount)Write a...
-
Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula in Programming Exercise 2.21.Use...
-
Write a method that converts milliseconds to hours, minutes, and seconds using the following header: public static String convertMillis(long millis) The method returns a string as...
-
Consider the case of J polluters and with abatement cost functions C j (e j ) and one pollution victim. Abatement costs are ordered from highest to lowest such that C 1 (e 1 )>C 2 (e 2 )>>C J (e J )....
-
Describe an algorithm that puts the first three terms of a sequence of integers of arbitrary length in increasing order.
-
Think of ways in which you can practice social support for others, convincing them through every communication that they are valued individuals. lop1
-
On January 1, 1997, Wilmes Floral Supplies borrowed $2,413 from Bower Financial Services. Wilmes Floral Supplies gave Bower a $2,500 note with a maturity date of December 31, 1998. The note specified...
-
Refer to Examples 19 and 23 in the chapter. Firm D holds 10,000 gallons of whiskey in inventory on October 31, 2010, that costs $225 per gallon. Firm D contemplates selling the whiskey on March 31,...
-
36) Based on Dow theory, when the financial analyst waits for the corrective movements, which could last for three weeks to three months then the market is said to be in__________________________. a....
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 654 public static int reverse(int number) // Return true if number is a palindrome public...
-
A pentagonal number is defined as n(3n1)/2 for n = 1, 2, . . ., and so on. Therefore, the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a...
-
Tom, Jan, and Julie are IS majors at Great State University. These students have been assigned to a class project by one of their professors, requiring them to develop a new Web-based system to...
-
Scatterplot. In Exercises 5-8, use the sample data to construct a scatterplot. Use the first variable for the x-axis. Based on the scatterplot, what do you conclude about a linear correlation? Pulse...
-
Given two fair six sided dice and a standard deck of 52 playing cards, calculate the probability of a rolling a sum of 7 or 11 and drawing three cards in which at least one is a face card.
-
z Scores. In Exercises 5-8, express all z scores with two decimal places. 5. Diastolic Blood Pressure of Females For the diastolic blood pressure measurements of females listed in Data Set 1 "Body...
-
A jury of 12 is to be created from a pool of 20 men and 10 women. What is the probability that all 12 on the jury will be men?
-
Reproduced below from Farthington Supply's accounting records is the accounts receivable subledger along with selected general ledger accounts. Dec. 31/19 Balance Credit sales in 2020 General Ledger...
-
Caryn offered to tutor Dottie in business law for six hours on the day before the final exam in return for $100. Dottie responded, Let me think about it for a day, okay? Two hours later Jim offered...
-
During 2012, Cheng Book Store paid $483,000 for land and built a store in Georgetown. Prior to construction, the city of Georgetown charged Cheng $1,300 for a building permit, which Cheng paid. Cheng...
-
In Java, methods must include all of the following except _____________. a. A call to another method b. A declaration c. Curly braces d. A body
-
All method declarations contain _____________. a. Arguments b. One or more explicitly named access specifiers c. Parentheses d. The keyword static
-
A public static method named computeSum() is located in ClassA. To call the method from within ClassB, use the statement _____________. a. ClassA.computeSum(); b. ClassB(computeSum()); c....
-
This table shows the stock returns for Stock A and Stock B in three different scenarios. The first column shows how likely each of the three scenarios is. The risk-free rate is 5%. Calculate the...
-
The STI Desk Company manufactures student desks that it sells for $80 per unit. Current cost information is as follows: Variable Costs: Direct Material per Desk - $20 Direct Labour per Desk - $15...
-
8. Implied interest rate and period Aa Aa Consider the case of the following annuities, and the need to compute either their expected rate of return or duration Jacob needed money for some unexpected...
Study smarter with the SolutionInn App