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
Which website allows you to host your podcast for at a cost that includes your domain name?
scZoUnD [109]

Answer: WordPress

Explanation:It is a kind of website where you can publish your content on any thing and can also buy domain there,if wanted

8 0
3 years ago
Read 2 more answers
Select one of the following strategies: active listening, sandwich technique, constructive feedback. in 2-5 paragraphs, define a
Neporo4naja [7]

Answer:

Active listening is used to make things more clear when talking to other people. Whether it is on the phone or face to face active listening can reduce any unwanted barriers of communication. Getting rid of barriers can help a company save time rather than trying to explain things multiple times. This ultimately would lead to more goods or services being produced therefore making the company more efficient. There are many more reasons why this workplace tacit is useful but I personally believe this is one of the more used ways.

I really hope this works for you!

5 0
3 years ago
Which of the following statements represents the number of columns in a regular two-dimensional array named values?
puteri [66]

Answer:

(a) values[0].length

Explanation:

In programming languages such as Java, an array is a collection of data of the same type. For example, a and b below are an example of an array.

a = {5, 6, 7, 9}

b = {{2,3,4}, {3,5,4}, {6,8,5}, {1,4,6}}

But while a is a one-dimensional array, b is a regular two-dimensional array. A two-dimensional array is typically an array of one-dimensional arrays.

Now, a few thing to note about a two-dimensional array:

(i) The number of rows in a 2-dimensional array is given by;

<em>arrayname.length</em>

For example, to get the number of rows in array b above, we simply write;

<em>b.length </em>which will give 4

(ii) The number of columns in a 2-dimensional array is given by;

<em>arrayname[0].length</em>

This is with an assumption that all rows have same number of columns.

To get the number of columns in array b above, we simply write;

<em>b[0].length </em>which will give 3

Therefore, for a regular two-dimensional array named values, the number of columns is represented by: values[0].length

5 0
3 years ago
Carl is beginning a digital forensic investigation. he has been sent into the field to collect a machine. when he arrives, he se
postnew [5]

Answer:

Volatile memory analysis

Explanation:

volatile data analysis in a computer's memory dump memory forensics is used by information security specialists to examine and identify assaults or harmful actions that leave no clearly identifiable trails on hard disk data which os what Carl decides to preserve as much data as possible by capturing data in memory

6 0
2 years ago
a problem exists when the current condition differs from a desired condition. This idea defines which step in problem-solving?
zhannawk [14.2K]

In algorithm the idea defines a decision box

5 0
3 years ago
Read 2 more answers
Other questions:
  • Enter a formula in cell b7 to calculate the average value of cells b2:b6
    13·1 answer
  • All of the following are current key technology trends raising ethical issues except:_________
    13·1 answer
  • How we know that how many domain exist in window server 2012?
    14·1 answer
  • Identify a stressor in your life. Conduct an internet search to locate at least two reliable sources of information on effective
    6·1 answer
  • Code written by computer programmers is translated to binary code, so computers can understand the instructions. True or False
    7·1 answer
  • For example, consider a file with protection mode 644 (octal) contained in a directory with protection mode 730. How might the f
    9·1 answer
  • Write a program that will read two floating point numbers (the first read into a variable called first and the second read into
    13·1 answer
  • How many types of sharing of Google Forms are possible?
    15·1 answer
  • In dos operating system ,write a command to delete the directory as well as the files of the directory ''world'' on drive E.
    15·1 answer
  • Whats the difference between Input and Output? Give and example of an example on a M:B​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!