Write a program that reads an integer between 0 and 1000 and adds all the digits in
Question:
Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14.
Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.
Here is a sample run:
Enter a number between 0 and 1000: 999
The sum of the digits is 27
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 88% (9 reviews)
Program Plan Create a class called SumOfDigits Prompt and read a number from the console Calculate t...View the full answer
Answered By
Fahmin Arakkal
Tutoring and Contributing expert question and answers to teachers and students.
Primarily oversees the Heat and Mass Transfer contents presented on websites and blogs.
Responsible for Creating, Editing, Updating all contents related Chemical Engineering in
latex language
4.40+
8+ Reviews
22+ 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 program that reads an integer and displays all its smallest factors in increasing order. For example, if the input integer is 120, the output should be as follows: 2, 2, 2, 3, 5.
-
Suppose you have a program that reads an integer, followed by a character, using the following prompt and READ statement: WRITE(Enter an integer and a character READ (intval, charval); When you run...
-
Write a program that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. Enter a negative number to...
-
Discuss sources of revenues Explain the importance of prices and volume in revenue budgeting Clarify why revenues are often ignored in nursing budgets Discuss when revenues should be considered in...
-
Estimate the limit numerically or state that the limit does not exist. If infinite, state whether the one-sided limits are or - . 33. 35. tan _ 2 sin cos lim 4 lim cos
-
Find the distance between each pair of points. Round your answer to the nearest tenth, if necessary. # y x
-
Petitioner Atlantic Marine Company was a contractor located in Virginia. It entered into a subcontract with J-Crew Management, Inc., a Texas corporation, that contained a forum-selection clause...
-
Weston Corporation manufactures auto parts for two leading Japanese automakers. Nancy Evans is the management accountant for one of Westons largest manufacturing plants. The plants general manager,...
-
Find the perimeter of the figure shown. Express the perimeter using the same unit of measure that appears on the given sides. 13 yd Perimeter = 5 yd 5 yd 13 yd 18 yd 18 yd
-
A Global private bank is aggressively looking to leverage technology to improve customer experience and reduce operational costs. Over the last few years, it has tied up with at least five startups...
-
Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays...
-
Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample...
-
It is proposed to use one 32- and one 28-in pump from Fig. 11.7a in parallel to deliver water at 60F. The system-head curve is Hs = 50 + 0.3Q2, with Q in thousands of gallons per minute. What will...
-
A piece of glass at 89 o C is placed in 0.75 kg of ethyl alcohol initially at 12 o C. The final temperature of the glass/ethyl alcohol mixture is 18 C. Determine the mass of the piece of glass?
-
A pendulum mass is attached to a 1.3 meter string. If the mass is initially dropped from a horizontal position as shown in the diagram, what is the speed in m/s of the mass at the bottom?
-
A rock dropped near the surface of the Earth travels D(t) = 16t feet during the first t seconds of the fall. 1. Free Fall Velocity (a) Fill out the partial table for the first 3 seconds: t D(t) 0 1 2...
-
Discuss the need for education reform in the United States to create more equal educational opportunities for low-income families? What percentage of your state's four-year-old's are provided a state...
-
A block of mass m = 14,9 kg is attached to the free end of a light string wrapped around a reel of radius R = 0, 47 m and mass M = 9,1 kg. The reel is a uniform disk and fixed on an axis about which...
-
Refer to the information presented for Galenti, Inc. in P17-9B. Additional information: 1. Accounts Payable is used for merchandise purchases. 2. Prepaid expenses and accrued expenses payable relate...
-
A fast-food restaurant averages 150 customers per hour. The average processing time per customer is 90 seconds. a. Determine how many cash registers the restaurant should have if it wishes to...
-
Rewrite the PrintCalendar class in Listing 6.12 to display a calendar for a specified month using the Calendar and GregorianCalendar classes. Your program receives the month and year from the command...
-
Write the following method that shuffles an ArrayList of numbers: public static void shuffle(ArrayList list)
-
Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject then implement the Triangle class. Write a test program...
-
An analysis of the activities needed to produce each product has been conducted. In addition, estimates have been developed. These are in the table below. Match the OH rate with the activity for each...
-
Service business 1. You are required to form a small business (Service business) 2. Explain the name and nature of the business, location, mission and objectives of the company. Assume the business...
-
Cost of utilities Cost per month (In dollars) $20,000 4. The cost of utilities depends on how many wards the hospital needs to use during a particular month. During months with activity under 2,000...
Study smarter with the SolutionInn App