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
4vir4ik [10]
3 years ago
13

6.2 Sum the digits in an integer (Sum the digits in an integer) Write a method that computes the sum of the digits in an integer

. Use the following method header: public static int sumDigits(long n) For example, sumDigits(234) returns 9 (= 2 + 3 + 4). (Hint: Use the % operator to extract digits and the / operator to remove the 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));
Computers and Technology
1 answer:
liberstina [14]3 years ago
4 0

Answer:

The method sumDigits() and the test program is given in the explanation section below:

Explanation:

import java.util.Scanner;

public class num8 {

   public static int sumDigits(long n){

       long sum = 0;

       while (n != 0)

       {

           sum = sum + n % 10;

           n = n/10;

       }

       return (int)sum;

   }

   public static void main(String[] args) {

       System.out.println("Enter a long integer");

       Scanner in = new Scanner(System.in);

       long digit = in.nextLong();

       System.out.println(sumDigits(digit));

   }

}

The steps required to implement this method are given in the question. A while is used to repeatedly extract and remove the digit until all the digits are extracted. In the main method, the Scanner class is used to prompt a user to enter a digit, the method is called and the digit is passed as an argument.

You might be interested in
9. Select the correct answer.
mihalych1998 [28]

Answer:

I believe the answer is exclusive but im not 100% sure

5 0
3 years ago
Rosanna is a middle school teacher. She has installed a spreadsheet program in her computer that tracks the grades and attendanc
Lana71 [14]

The computer software that should be installed on Rosanna's computer is application software.

The information regarding the application software is as follows:

  • It is the software where the activity is to be performed.
  • The example like a spreadsheet software, presentation software, database software, etc.

Therefore we can conclude that the computer software that should be installed on Rosanna's computer is application software.

Learn more about the software here: brainly.com/question/1022352

8 0
3 years ago
What is network topology? PLZZZ HURRY
Mashcka [7]

Answer:

Network topology is the arrangement of the elements (links, nodes, etc.) of a communication network. Network topology can be used to define or describe the arrangement of various types of telecommunication networks, including command and control radio networks, industrial field busses and computer networks.

7 0
3 years ago
50 Points being offered for the fastest and most correct response<br><br> How do I fix this?
kolezko [41]
Hi there!

Try resetting your browser, clearing your cache, and rebooting your computer.. If none of these work, or you've already tried these, let me know..

Hope this helps! ☺♥
5 0
3 years ago
Read 2 more answers
Which of the following is not a benefit of normalization?
mixer [17]

Answer:

The answer is option (4) Maximize redundancy as normalization minimizes redundancy of data.

Explanation:

Normalization of databases leads to minimization of data redundancy in databases. It doesn't maximize data redundancy. Data redundancy leads to wastage of resources. Normalization of databases minimizes insertion anomolies. Normalization of databases minimizes deletion anomolies. Normalization of databases minimizes updation anomolies.  So , the answer to the question is option (4) maximize redundancy.

8 0
3 years ago
Other questions:
  • Once the technology for the collection of solar power is in place what will be two benefits of its use
    9·1 answer
  • When naming a file you should use the _____________ instead of a space in a filename.
    6·1 answer
  • Who is the last person appointed to the u.s supreme court
    11·1 answer
  • Which of the following statements invokes the GetDiscount function, passing it the contents of two Decimal variables named decSa
    8·1 answer
  • Write an algorithm to determine a students final grade and indicate whether it is passing or failing .the final grade is calcula
    12·1 answer
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • Heidi uses her computer to write articles for a newspaper. She uses a program to listen to the articles before she submits them
    5·1 answer
  • Explain the term information security?​
    9·1 answer
  • If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook? (6 points)
    14·1 answer
  • What is a possible weakness of an expert-novice pair?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!