Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program SumDigits.java that perform the following: Define a function addDigits that computers the sum number 2345 returns 14 (2+3+4+5). Write a program that

"Write a" program SumDigits.java that perform the following:

Define a function addDigits that computers the sum number 2345 returns 14 (2+3+4+5).

"Write a" program that asks user to enter 4 digit a number and print out the sum of its digits using the method above. if the user enters a number that is not 4 digits, print an invalid input message. Repeat until user wants to quit.

sample output

Enter a 4 digit number (-1 to quit): 2345

Sum of the digits of 2345 is 14

Enter a 4 digit number (-1 to quit): 123456

Invalid input. Please enter a 4 digit number

Enter a 4 digit number (-1 to quit): 3456

Sum of the digits of 3456 is 18

Enter a 4 digit number (-1 to quit): -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Java program named SumDigitsjava that implements the described functionalit... 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

Payroll Accounting 2016

Authors: Bernard J. Bieg, Judith Toland

26th edition

978-1305665910, 1305665910, 1337072648, 978-1337072649

More Books

Students also viewed these Programming questions