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
Serggg [28]
3 years ago
9

(Reverse number) Write a program that prompts the user to enter a four-digit inte- ger and displays the number in reverse order.

Here is a sample run:
Computers and Technology
1 answer:
prohojiy [21]3 years ago
6 0

Answer:

The program in Python is as follows:

num = int(input("4 digit number: "))

numstr = str(num)

if(len(numstr)!=4):

    print("Number must be 4 digits")

else:

    numstr = numstr[::-1]

    num = int(numstr)

    print(num)

Explanation:

This prompts user for input

num = int(input("4 digit number: "))

This converts the input number to string

numstr = str(num)

This checks if number of digits is or not 4

if(len(numstr)!=4):

If not, the following message is printed

    print("Number must be 4 digits")

else:

If digits is 4,

This reverses the string

    numstr = numstr[::-1]

This converts the reversed string to integer

    num = int(numstr)

This prints the reversed number

    print(num)

You might be interested in
How much will your assignment be docked if you turn it in late?
o-na [289]
We don’t know ms.Fredrick, you’re on your own here
7 0
3 years ago
Read 2 more answers
Given an array as follows
slava [35]

Answer:

1) Method calcTotal:

  1. public static long calcTotal(long [][] arr2D){
  2.        long total = 0;
  3.        
  4.        for(int i = 0; i < arr2D.length; i++ )
  5.        {
  6.            for(int j = 0; j < arr2D[i].length; j++)
  7.            {
  8.                total = total + arr2D[i][j];
  9.            }
  10.        }
  11.        
  12.        return total;
  13.    }

Explanation:

Line 1: Define a public method <em>calcTotal</em> and this method accept a two-dimensional array

Line 2: Declare a variable, total, and initialize it with zero.

Line 4: An outer for-loop to iterate through every rows of the two-dimensional array

Line 6: An inner  for-loop to iterate though every columns within a particular row.

Line 8: Within the inner for-loop, use current row and column index, i and j, to repeatedly extract the value of each element in the array and add it to the variable total.

Line 12: Return the final total of all the element values as an output

Answer:

2) Method calcAverage:

  1. public static double calcAverage(long [][] arr2D){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            for(int j = 0; j < arr2D[i].length; j++)
  8.            {
  9.                total = total + arr2D[i][j];
  10.                count++;
  11.            }
  12.            
  13.        }
  14.        
  15.        double average = total / count;
  16.        
  17.        return average;
  18.    }

Explanation:

The code in method <em>calcAverage</em> is quite similar to method <em>calcTotal</em>. We just need to add a counter and use that counter as a divisor of total values to obtain an average.

Line 4: Declare a variable, count, as an counter and initialize it to zero.

Line 11: Whenever an element of the 2D array is added to the total, the count is incremented by one. By doing so, we can get the total number of elements that exist in the array.

Line 16: Use the count as a divisor to the total to get average

Line 18: Return the average of all the values in the array as an output.

Answer:

3) calcRowAverage:

  1. public static double calcRowAverage(long [][] arr2D, int row){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            if(i == row)
  8.            {
  9.                for(int j = 0; j < arr2D[i].length; j++)
  10.                {
  11.                    total = total + arr2D[i][j];
  12.                    count++;
  13.                }
  14.            }
  15.            
  16.        }
  17.        
  18.        double average = total / count;
  19.        
  20.        return average;
  21.    }

Explanation:

By using method <em>calcAverage </em>as a foundation, add one more parameter, row, in the method <em>calcRowAverage</em>. The row number is used as an conditional checking criteria to ensure only that particular row of elements will be summed up and divided by the counter to get an average of that row.

Line 1: Add one more parameter, row,

Line 8-15: Check if current row index, i, is equal to the target row number, proceed to sum up the array element in that particular row and increment the counter.

5 0
3 years ago
Describe some common types of charts.​
Mekhanik [1.2K]
Bar chart.
Pie chart.
Line chart.
4 0
2 years ago
Read 2 more answers
What are the different ways one can adjust their communication in order to decrease noise?
soldier1979 [14.2K]

Answer

You can  whisper,write notes, text, e-mail, body language, and even use a sign language.

Explanation

By adjusting your communication in these ways one can decrease noise. Whispering is where you speak softly to someone where the information will be only heard by the person you are addressing and this will not make any noise. Also use of a text or an email where the message will be delivered electronically but not verbally. Then there is the body language which is a nonverbal  but a physical behavior used to express a certain information or also one can use sign language.

5 0
3 years ago
Read 2 more answers
Assume the method doSomething has been defined as follows: public static void doSomething (int[] values, int p1, int p2) { int t
Dmitriy789 [7]

Answer:

The answer to this question is option "b".

Explanation:

In the method definition, we perform swapping. To perform swapping we define a variable "temp" that swap values of variable p1 and p2 and store in array that is "values". and other options are not correct that can be defined as:

  • In option a, It does not insert any new value in array because we do not pass any value in function.
  • In option c, The function does not copy and assign a value in a new array because in this function we not assign any new array.  
  • In option d, It is incorrect because it can not move an element into high index position.
8 0
2 years ago
Other questions:
  • Which type of operating system is usually used in personal computers?
    11·1 answer
  • Dust buildup inside a desktop PC case can be managed effectively by ____.
    7·2 answers
  • What component of Kerberos is responsible for storing keys for encrypting and decrypting data in the authentication process?
    13·1 answer
  • When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
    11·2 answers
  • Which of the following does your textbook recommend for preparing PowerPoint slides? Group of answer choices
    9·1 answer
  • Jeremy is working with a team that is creating an application using attributes and associated methods. What type of programming
    8·1 answer
  • Mika forgot to put in the function name in his function header for the code below. What would be the best function header?
    12·2 answers
  • Write the Q basic program to find the area of room.​
    10·1 answer
  • Critical Thinking Questions
    9·2 answers
  • Database queries is an example of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!