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
13) When developing film, how do you dispose of fixer as opposed to developer?
MAVERICK [17]

Answer:

B) Developer is poured down the drain while fixer can be reduced

Explanation:

The effluents produced during photographic processing includes, wash water, bleach, fixer, and developer

The developer is an alkaline solution, with a pH of approximately 10.0, while the pH of the fixer is about 4.3, it is therefore, acidic

The rate of discharge of the developer to the fixer is 2 to 1, and the exhausted developer, fixer and process effluents combined are neutral and can be handle by the the treatment works and the drain pipes

Fixer which remain clear can be reused for more than a day, while the spent basic Developer and the acidic Spent Stop Bath can be combined to form a neutral solution, having a pH of approximately 7, which make them less hazardous to be disposed off down the sink into the drain

Therefore, <em>developer is poured down the drain while fixer can be reused</em>

6 0
3 years ago
Which type of front usually brings thunderclouds and storms
IrinaVladis [17]
Your anwser will be d
5 0
3 years ago
Read 2 more answers
Write a function endpoints that takes a list of numbers (eg. [5, 10, 15, 20, 25]) and returns a new list of only the first and l
Ne4ueva [31]

I included a picture of my code below. Best of luck with your assignment.

5 0
3 years ago
WAP to input the rating of a movie, and print as per the given criteria:
vodka [1.7K]

Answer:

What is the question?

Explanation:

8 0
2 years ago
Item 3Item 3 John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastruc
White raven [17]

Answer:

Replacing computer parts.

Explanation:

John replaces faulty computer parts, such as DVDs, hard drives, ram cards, wires etc. John can also replace the whole motherboard or clean it (for dust).

Computer parts not functioning properly or dying is a common problem in computer systems. Motherboard, the circuit that holds all the components of a computer, like CPU, Ram and Hard disk, can also fail or die.

5 0
3 years ago
Other questions:
  • Shut down and unplug the computer. Remove the CPU case lid. Locate the various fans, and then use compressed air to blow dirt ou
    13·2 answers
  • Which directory in the FHS stores programs and configuration information that can only be executed and modified by the root user
    10·1 answer
  • Continuous reboots of a Windows host upon encountering a persistent stop error might be caused by Startup and Recovery configura
    10·1 answer
  • Application partitioning gives developers the opportunity to write application code that can later be placed on either a client
    7·1 answer
  • Find functions f1 and f2 such that both f1 and f2 are O(g(n)), but f1(n) is not O(f2)
    6·1 answer
  • Describe a scenario for which a find unmatched query could be used.
    12·1 answer
  • The keys in the computer's keyboard are represented by a numeric code agreement (ASCII). For example A is 65 and a is 97.
    12·1 answer
  • Use the drop-down menu to correctly identify the numbering system.
    7·1 answer
  • TLE(ICT)-10
    10·1 answer
  • What has global css rulesets of an angular 8 project mcq.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!