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]
3 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]3 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
What is the correct name for the words Home, Insert, Design, Layout, References, etc. in the ribbon in Word 2016?
KIM [24]

Answer:

Option (B) i.e.,Tabs is the correct option.

Explanation:

Because the followings are the tabs in the ribbon of Ms Word 2016, with the help of the tabs we can edit, update, modify, design, change or insert layout and also we can insert themes, etc in our document. These tabs are important to create our document attractive and provide good designs in the document. We also create business cards, invitation card and other important things with the help of tabs.

7 0
3 years ago
Read 2 more answers
Answer quickly!!!
ioda

Answer: Harry should check that font he has used are readable on every page and element of his website


Harry should check that all images have alt texts

Explanation: edmentum

7 0
1 year ago
Brock wants to use several images on his hiking blog. However, the images are making his pages load very slowly. Explain to Broc
attashe74 [19]
First brock has to make sure he has all the hiking gear, like a camel back, gloves, the right pair of shoes. and then if he wants to take pictures he should buy a go-pro so he doesn't really have to move will the go-pro will record or take pictures.
hope i helped 0-0 ;p
plz mark brainly
5 0
3 years ago
The security administrator for Corp wants to provide wireless access for employees as well as guests. Multiple wireless access p
Artemon [7]
It’s B I took the test
7 0
3 years ago
Folktales have characters with good or bad traits here are some good wise clever kind hardworking I have too add one more good t
s2008m [1.1K]

Answer: good generous bad greedy

Explanation:

5 0
3 years ago
Other questions:
  • Which of the following functions and expressions will convert the ASCII character "Z" to its numeric equivalent ASCII code?
    7·1 answer
  • During the past decade ocean levels have been rising faster than in the past, an average of approximately 3.1 millimeters per ye
    14·1 answer
  • Which of the following will most likely result in a decrease in population?
    11·2 answers
  • _____ are considered to be the most important element in a computer-based information system.
    8·1 answer
  • Which rotation speed is not a typical spindle rotation speed for magnetic hard drives?3100; 5400; 7200; 10000
    8·1 answer
  • What are copyright laws? Authority to reprint an original work as long as it's not for profit Entitlement to use and sell anothe
    15·2 answers
  • Pls tell me the answer pls i need the answer
    6·2 answers
  • Program Convert Measurements:
    15·1 answer
  • Write a program that gets three input characters which are user's initials and displays them in a welcoming message. Then gets i
    12·1 answer
  • What does an arrow after a command indicate
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!