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
trapecia [35]
3 years ago
6

Write a program with class name Digits that prompts the user to input a positive integer and then outputs the number reversed an

d the sum of the digits. For example, if the user enters the number 3456, then your program should output 6543 and the sum as 18. Use a while loop. Hint: use the mod operator and 10 as divider to find the right most digit and to update the value of controlling expression
Computers and Technology
1 answer:
mr Goodwill [35]3 years ago
7 0

Answer:

Written in Python:

inputnum = int(input("User Input: "))

outputnum = 0

total = 0

while(inputnum>0):

     remainder = inputnum % 10

     outputnum = (outputnum * 10) + remainder

     inputnum = inputnum//10

     total = total + remainder

print("Reverse: "+str(outputnum))

print("Total: "+str(total))

Explanation:

This prompts user for input

inputnum = int(input("User Input: "))

This initializes the reverse number to 0

outputnum = 0

This initializes total to 0; i.e. sum of each digit

total = 0

The following iteration gets the reverse of user input

<em>while(inputnum>0): </em>

<em>      remainder = inputnum % 10 </em>

<em>      outputnum = (outputnum * 10) + remainder </em>

<em>      inputnum = inputnum//10 </em>

<em>      This adds each digit of user input</em>

<em>      total = total + remainder </em>

This prints the reversed number

print("Reverse: "+str(outputnum))

This prints the sum of each digit

print("Total: "+str(total))

You might be interested in
Translate the following pseudocode for randomly permuting the characters in a string into a C++ program.
Svetllana [295]

Answer:

d

Explanation:

salak sensin kolay gelsin

6 0
3 years ago
In this assignment, you will use the Microsoft Threat Modeling Tool (TMT-2016).
tresset_1 [31]

Answer:

yes yes yes yes yes yes yes

5 0
3 years ago
Describe how place value is used in the binary number system. How is it similar or different from the way place value is used in
daser333 [38]
The binary number system is also referred as base-2 numeral system. The numeric values in the binary system are represented with only two symbols "0" and "1". The base 10 number system on the other hand is the usual number system that uses decimal numbers.
In the binary system the number to the left of the point is a whole number and every number further left gets 2 times bigger. The first digit on the right means halves and every number further right is 2 times smaller.
In the base 10 system number greater than 1 appear to the left of a decimal point. Values that are a fraction appear to the right of the decimal point. Every number further  left is 10 times bigger, and right 10 times smaller.







7 0
3 years ago
Host A and Host B are connected via a 10 Km, 100 Mbps link. Suppose A is transferring multiple 2 KB segments to B using rdt3.0.
stich3 [128]
ANSWER: Sender utilization
4 0
3 years ago
Write a full class definition for a class named Averager, and containing the following members:______An data member named sum of
alina1380 [7]

Answer:

  1. public class Averager {
  2.    private int sum;
  3.    private int count;
  4.    public Averager(int sum, int count) {
  5.        this.sum = 0;
  6.        this.count = 0;
  7.    }
  8.    public int getSum(){
  9.        return sum;
  10.    }
  11.    public void add( int num){
  12.        this.sum+=num;
  13.        this.count++;
  14.    }
  15.    public int getCount(){
  16.        return this.count;
  17.    }
  18.    public double getAverage(){
  19.        double ave = (int)this.sum/this.count;
  20.        return  ave;
  21.    }
  22. }

Explanation:

  • Lines 1-3 contains the class declaration and the member (data fields)
  • Lines 4-7 is the constructor that initializes the fields to 0
  • Lines 8-10 is the method that returns the value of sum getSum()
  • lines 11-14 iss the method add() that adds a number to the member field sum and increases count by 1
  • lines 15 - 17 is the method that returns total count getCount()
  • Lines 18-21 is the method getAverage() That computes the average and returns a double representing the average values

6 0
4 years ago
Read 2 more answers
Other questions:
  • List five characteristics of a series circuit
    9·1 answer
  • (a) Write a SCHEME function (make-change n den) which outputs a list of change specifications. Namely, a call (make-change 11 (l
    8·1 answer
  • Darren wants to substitute every occurence of the word bulky in his spreadsheet with the word strong. which of these options sho
    11·1 answer
  • Which of the following is not a compilation error? Group of answer choices a. Placing a semicolon at the end of the first line o
    13·1 answer
  • What is entered into a cell that is typically numeric and can be used for calculations?
    9·2 answers
  • From a database point of view, the collection of data becomes meaningful only when it reflect
    8·1 answer
  • It's the same drop-down answers for both.
    15·1 answer
  • What is the music form for the song "Sunflower?
    10·2 answers
  • 7. In order to check your following distance, use a fixed object and count seconds.
    5·2 answers
  • Which of the following is one of the tools used by a Python IDE that helps prevent syntax errors?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!