1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ivanshal [37]
4 years ago
15

For example, sumDigits(234) returns 9 (= 2 + 3 + 4). (Hint: Use the % operator to extract digits and the / operator to remove th

e extracted digit. For instance, to extract 4 from 234, use 234 % 10 (= 4 ). To remove 4 from 234, use 234 / 10 (= 2 3 ). 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 then displays the sum of all its digits. So in your main method you'd call sumDigits() like this and print what it returns. For example: System.out.println("Sum of the digits in the number 1234 is: " + sumDigits(1234)); Please watch this video on how to export your Java project from Eclipse:
Computers and Technology
1 answer:
madam [21]4 years ago
7 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

       System.out.print("Enter an integer: ");

       int number = input.nextInt();

 System.out.println("Sum of the digits in the number " + number + " is: " + sumDigits(number));

}

public static int sumDigits(int number){

       int remainder = (int)Math.abs(number);

       int sum = 0;

       

       while(remainder != 0){

           sum += (remainder % 10);

           remainder = remainder / 10;

       }

       return sum;

   }    

}

Explanation:

- Initialize two variables to hold <em>remainder</em> and <em>sum</em> values

- Initialize a while loop operates while the <em>remainder</em> is not equal to zero

- <u>Inside the loop</u>, extract digits and assign these digits into <em>sum</em>. Remove extracted digits from the <em>remainder</em>

- When all the digits are extracted, return the <em>sum</em> value

- Inside main, get input from the user and call the method

You might be interested in
How do you make someone brainlest
HACTEHA [7]

Answer:

When you ask a question, people have to option to responds and when you have two different users respond on your question, there is the option to give one of them the Brainliest award for the best answer.

Hope this Helps!

4 0
4 years ago
Read 2 more answers
​Coca-cola has developed a video ad campaign that encompasses several different viewing platforms including​ tv, digital,​ mobil
SOVA2 [1]
Integrated Marketing Communications is an approach that connects or linked all types of communication to be used in campaigning a product. So, coca cola has developed a video ad campaign that encompasses several different viewing platforms including tv, digital, mobile, and social media, this example shows that using the IMC approach you can integrate all promotional tools for a product.
7 0
3 years ago
What is the difference between sound proofing a room and acoustically treating a room?
Sergio [31]
The sound proof room has no sound at all, and an acoustically treated room has small sounds.
3 0
3 years ago
The Arrange All function is used to organize multiple open workbooks at once. Select the correct navigational path to
ElenaW [278]

Answer:

1. View

2. Window

3. Arrange all

Explanation:

I did the assignment on edgenuity

5 0
3 years ago
Read 2 more answers
What is the function of mail merge
Korolek [52]

A tool for producing large numbers of douments with the same content (APEX VERIFIED)

8 0
3 years ago
Read 2 more answers
Other questions:
  • A user is trying to delete a file located on an NTFS volume on his Windows 8 computer but is unable to do so. Why is this?
    11·1 answer
  • What is the code for loading image in matlab
    15·1 answer
  • The ____________ deals with the well-being of the EMT, career progression, and EMT compensation. Select one: A. EMS administrato
    9·1 answer
  • A group of cells is called a<br><br> Excel
    5·1 answer
  • What symbol is used for an assignment statement in a flowchart?
    8·1 answer
  • This OS was created by a developer named Torvalds.
    7·1 answer
  • How do you make a ringtone on earsketch
    9·1 answer
  • 1) Given what you have learned about computers and information technology thus
    6·1 answer
  • Why is being distracted by the sights and sounds of our devices dangerous?​
    12·1 answer
  • Assume the user responds with a 3 for the first number and a 5 for the second number.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!