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
Match each network maintenance tool with the purpose that is most closely identified with that tool - Loopback plug - Protocol a
Artist 52 [7]

Solution :

  • Loopback plug --- confirm interface functionality

It is a connector that is used to diagnose the transmission problems.

  • Protocol Analyzer --- Analyze network traffic

It is used to capture and analyze the signals as well as data traffic.

  • Throughput tester - Measure link speed
  • Time Domain Reflectometer (TDR) - Determining the location of cable fault

It is used in determining the characteristics of the electrical lines by observing the reflected waveforms

  • Locating a specific cable - Toner probe

3 0
2 years ago
true or false : The incorrect attitude towards driving is the cause of most collisions among teenage drivers.
natulia [17]
That is true your state of mind is what matters most 

4 0
3 years ago
Read 2 more answers
In BitTorrent, suppose Alice provides chunks to Bob throughout a 30-second interval. Will Bob necessarily return the favor and p
MakcuM [25]

Answer:

It will not necessary that bob will provide chunks to Alice.

Explanation:

Alice has four neighbors of Bob so he will send message to her, but this might not occur if Alice provides chunks to Bob.

Overlay is the network that build at the top of other network.It is a telecommunication network that supported by its own infrastructure.

It encapsulates one packet inside an other packet.

It is a method of creating layers of network that can be used to run multiple virtualized layers on the top pf other network.

It provides new security benefits.

Does Overlay include Routers

Overlay is a file sharing system in which nodes participating and create logical links between them.So overlay network does not include routers.

Edge in overlay

 It is a logical network in which nodes are connected using virtual or logical links.

5 0
3 years ago
Terry visits the website www.examplewebsite.org. What can you gather about the site from the domain?
Alja [10]
Answer: B

Explanation: This question asks the student to consider the domain .org. The student needs to know that org is short for organization. This would point to option B. For option A to be true, the domain would need to be .com. Option C and D couldn’t be true, as there is no domain to point to these options. For option E to be true, the domain would need to be .gov.

Hope this helps! Comment below for more questions.
3 0
3 years ago
William would like to sort a list of items after the data is already entered.
kari74 [83]

Answer:

Database software

Explanation:

6 0
3 years ago
Other questions:
  • (Java) Can anyone help me with this ?? The skeleton of the code must be same as the image.
    6·1 answer
  • ) Consider a router that interconnects four subnets: Subnet 1, Subnet 2, Subnet 3 and Subnet 4. Suppose all of the interfaces in
    11·1 answer
  • Which javascript method should you use if you want to specify a message string to appear on your web page as it loads?
    13·1 answer
  • Megan has written the following rough draft for her assignment. Choose the correct way to complete each sentence. Sarah is creat
    13·1 answer
  • What organization is responsible for the registration of Internet domain names?
    14·1 answer
  • What is the IEEE 802 standards name for a wireless network that is limited to one person's workspace?
    14·1 answer
  • Iciples UI
    12·1 answer
  • How do you copy a file​
    9·1 answer
  • !!! 20 points !!!!!
    15·1 answer
  • how many squares can be formed by connecting four of the dots in this 5x5 array? (make sure to consider all types of squares!)
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!