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
statuscvo [17]
3 years ago
13

Write a program that will take an integer and add up each of the number’s digits, count the number of digits in the number, and

then average the digits. You must use a while loop and % to access each of the individual digits. Use / to reduce the number so that you can average all of the digits.
Example: num = 123 can be taken apart with tempNum = 123 % 10 (which will pull off the 3), then tempNum = tempNum / 10 (will result in 12). Do this in a loop while the number is > 0.
 
Sample Data :
234
10000
111
9005
84645
8547
123456789
 
 
 Be sure to include print statements that will format the output as below.

Sample Output :
234 has a digit average of 3.0
 
10000 has a digit average of 0.2
 
111 has a digit average of 1.0
 
9005 has a digit average of 3.5
 
84645 has a digit average of 5.4
 
8547 has a digit average of 6.0
 
123456789 has a digit average of 5.0

Computers and Technology
2 answers:
Inga [223]3 years ago
5 0
For count digits, you could just convert it to a String and check the length
Sum digits, convert to string then seperate each character with charAt then convert it to numbers in the return statement.
Average digits you can convert it to a String and then convert them back after taking them apart.
STALIN [3.7K]3 years ago
5 0
Here is my solution:

import java.lang.System.*;

public class DigiMath {   

private static int countDigits(int number)
{
       int sum = 0;
       while(number > 0)
       {
           sum ++;
           number /= 10;
       }       return sum;   
}

private static int sumDigits(int number)   
{       
      int sum = 0;       
      while(number > 0) {
           sum += number % 10;
           number /= 10;
       }
       return sum;
}
   
   public static double averageDigits( int number )
   {
       int count = countDigits(number);
       if (count > 0) {
           return (double)sumDigits(number) / (double)count;      
       } else { 
            return 0; 
       } 
   }
   
   public static void PrintDigitAverage(int number)
   {
       System.out.printf("%d has a digit average of %1.1f\n", number, averageDigits(number));
   }
   
   public static void main(String[] args) 
   {
       // Method tests (run with java -ea)
       assert countDigits(12345) == 5 : "countDigits returns wrong count";
       assert sumDigits(12345) == 15 : "sumDigits returns wrong sum";
       assert averageDigits(12345) == 3.0: "averageDigits returns wrong average";

        PrintDigitAverage(234);
        PrintDigitAverage(10000); 
        PrintDigitAverage(111); 
        PrintDigitAverage(9005); 
        PrintDigitAverage(84645); 
        PrintDigitAverage(8547); 
        PrintDigitAverage(123456789);
   }
}


You might be interested in
Compared with traditional methods, the entire rapid application development (RAD) process is expanded and, as a result, the new
tensa zangetsu [6.8K]

Answer:

<u>False</u>

Explanation:

Note, the Rapid Application Development (RAD) software development approaches are noteworthy not for its expanded design details but for <u>its simplicity of the software development process.</u>

In other words, the RAD approaches while taking user preferences into the software development process, focuses on making the software design process more flexible, such as by employing the use of prototypes, and less unnecessary details.

5 0
2 years ago
In a flow chart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that
leonid [27]

Answer:

Option A(True) is the correct answer for the above question.

Explanation:

  • The flowchart is used to give the solution of a problem through the diagram in a step by step processor. It helps the user to understand the solution easily. For diagram, it uses many types of symbols that are fixed for every sequence just like An oval symbol represents the start and end of the flowchart which is fixed for every flowchart.
  • So for the decisions in a flowchart, the diamond symbol is used which is to make the decisions and it has two sides-- one is true and the other is false.
  • The decisions are used also to represent the loop structure which is also called the repetition structure because the loop is controlled by the help of decisions so the diamond box is also used for the loop
  • The above question-statement says that the decisions-controlled is used for the loop and for the decisions which are true because it is also described above.
8 0
3 years ago
Imagine the deep, low sound made by a tuba. Now, what is an example of a sound with a much higher pitch?
goblinko [34]
B.) The rumble of thunder.
I hope this helps. :p
7 0
2 years ago
Read 2 more answers
Joe has just started the Security Module. He wants to get through it as quickly as possible and take the Quiz. As he clicks thro
Scorpion4ik [409]

Answer:

Joe should read the explanatory text and complete the learning activities.

Explanation:

Given

See attachment for options

Required

Best strategy to get through the module

First off, rushing through the activities and taking guess for each question (as suggested by (a)) will not help him;

He may complete the activities but sure, he won't learn from the module.

Also, reading through the units without completing the activities is not an appropriate method because Joe will not be able to test his knowledge at the end of the module.

The best strategy to employ is to read through the units and complete the activities, afterwards (option (b)).

4 0
3 years ago
A(n) ____________ is a private data network that creates secure connections over regular internet lines.
Setler79 [48]
VPN is the correct answer
5 0
3 years ago
Other questions:
  • On an Android device, where can a user find the correct app to use to sync contacts and apps among devices?
    10·1 answer
  • _____ is the unauthorized entry into a computer system via any means
    9·1 answer
  • True or false: Your digital footprint is all the information about you online that only you post. Group of answer choices
    12·2 answers
  • Mary is entering her senior year of college. She has a meeting on Friday with her advisor to discuss her career plans.Mary is al
    15·1 answer
  • :If a process terminates, will its threads also terminate or will they continue to run? Explain your answer.
    14·1 answer
  • Is it possible for the front and rear references in a circular array implementation to be equal?
    8·1 answer
  • Proxy download for school
    15·2 answers
  • Helppppppppppppppp me please Can i have help for a ggogle class room
    5·1 answer
  • Write a method that makes the input string of sentences ending with and
    11·1 answer
  • Explain why the receptionist responded as indicated in the following scenario.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!