Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6.2 Using a method ( 10 points ): (Sum the digits in an integer) Write a java program SumDigByMethod.java that uses a method sumDigits(long number)

6.2 Using a method (10 points): (Sum the digits in an integer) Write a java program SumDigByMethod.java that uses a method sumDigits(long number) to calculate the sum of the individual digits in a user-input number (integer or long). The method sumDigits( ) returns an integer value. The user- input number can have up to 10 digits. Do not assume or force a specific number of digits. In your main( ) method, prompt the user to enter the number. Then make a call to sumDigits( ) and pass it on the number entered by the user. The method sumDigits( ) should then calculate the sum of digits and send it back to main( ). Displays the sum of digits from main( ) after main receives it from sumDigits( ). [While it is not mandatory, writing and using a numOfDigits( ) method to determine the number of digits in a number could help this one and the next program.]

Sample Run

This program uses a method sumDigits( ) to sum the digits in a number. Please enter the number: 1234 Printed from main( ): The number entered is: 1234

Making a call to sumDigits( ) Back in main( )

The sum of digits in the number 1234 is: 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

What is the core principle of revenue recognition?

Answered: 1 week ago

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago