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
kobusy [5.1K]
3 years ago
14

Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values in an arr

ay and print the array. Then reverse the array elements so that the first element becomes the last element, the second element becomes the second to last element, and so on, with the old last element now first. Do not just reverse the order in which they are printed; actually change the way they are stored in the array. Do not create a second array; just rearrange the elements within the array you have.
Computers and Technology
1 answer:
Svetllana [295]3 years ago
3 0

Answer:

//The Scanner class is imported to allow the program receive user input

import java.util.Scanner;

//The class Solution is defined

public class Solution {

   //The main method is defined here and signify the beginning of program execution

   public static void main(String args[]) {

       

       //Scanner object 'scan' is created to receive user input

       Scanner scan = new Scanner(System.in);

       //Prompt display to the user to enter size of array

       System.out.print("Enter the range of array: ");

       //User input is assigned to arraySize

       int arraySize = scan.nextInt();

       //userArray is initialized with arraySize as its size

       int[] userArray = new int[arraySize];

       

       //counter to count number of array element

       int count = 0;

       //while loop which continue executing till the user finish entering the array element

       while (count < arraySize){

           System.out.print("Enter each element of the array: ");

           userArray[count] = scan.nextInt();

           count++;

       }

       

       //A blank line is printed for clarity

       System.out.println();

       

       //for loop to print each element of the array on straight line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

       

       //A blank line is printed for clarity

       System.out.println();

       

       //for loop is use to reverse the array in-place

       for(int i=0; i<userArray.length/2; i++){

           int temp = userArray[i];

           userArray[i] = userArray[userArray.length -i -1];

           userArray[userArray.length -i -1] = temp;

       }

       

       //for loop to print each element of the reversed array on straight line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

     

   }

}

Explanation:

The program is commented to give detailed explanation.

The for-loop use in reversing the array works by first dividing the array into two half and exchanging the first half elements with the second half elements. The element from the first half is assigned to temp variable on each loop, then the element is replaced with the equivalent element from the second half. And the element from the second half is replaced with the value of temp.

You might be interested in
The key invention that enabled computers to go into every home and office is
Scrat [10]
<span><span />The Microprocessor is the key invention that enabled computers to go into every home and office. Microprocessor is a computer processor that enables the computer to run. It is also called as central processing unit. It is also a multipurpose and programmable device that accepts inputted data and process the data to provide an output. Microprocessor started from 8-bit design to 16bit, 32 bit, 64 bit and now it is produce a multi core design in the market. Faster and stronger design that can run heavier applications.</span>



8 0
3 years ago
Suppose there are 69 packets entering a queue at the same time. Each packet is of size 7 MiB. The link transmission rate is 1.7
svp [43]

Answer:

69.08265412 milliseconds

Explanation:

Lets first convert 7 MiB to bits

7*1024*1024*8=58720256 bits

Now convert bits to Gbits

58720256/10^{9}  =0.058720256 Gbits

Queuing Delay = Total size/transmission link rate

Queuing Delay= \frac{0.058720256}{1.7} =0.03454132706 seconds

Delay of packet number 3 = 0.03454132706*2=0.06908265412 seconds

or 0.06908265412= 69.08265412 milliseconds

7 0
3 years ago
Line formatting can be accomplished by using
schepotkina [342]

Answer:

How can line formatting be accomplished?

To format line spacing:

Select the text you want to format. Selecting text to format.

On the Home tab, click the Line and Paragraph Spacing command. A drop-down menu will appear.

Move the mouse over the various options. A live preview of the line spacing will appear in the document. Select the line spacing you want to use.

The line spacing will change in the document.

3 0
2 years ago
What was the first carbonated drink to be introduced in the US?
adelina 88 [10]
Taco bell...........................................................................................................................................................................

6 0
3 years ago
Hard disk works on the following technologies: (i) Technology used within the hard drive to read &amp; write data to the drive a
Alex787 [66]

Answer:

The green-blue circuit board you can see in the first photo includes the disk controller, a circuit that allows the computer to operate the drive's mechanisms and read/write data to and from it. ... A small hard drive typically has only one platter, but each side of it has a magnetic coating

Explanation:

8 0
2 years ago
Other questions:
  • Lydia used software to calculate the budget for each department. To create this budget, she used a _____.
    7·2 answers
  • You are out on the water. you do not understand what another boater intends to do. what sound signal should you make?
    14·1 answer
  • A word that has a specific, predefined meaning in a programming language is called
    8·1 answer
  • GPS data can be used to track the rate and direction of plate movement. If a GPS unit measures a latitude velocity of 28.2 mm/yr
    8·1 answer
  • Why do you think that so many of these sources have similar names?
    9·1 answer
  • The ______________ shows that you have fully researched the topic and gives you a chance to prove your claim.
    8·1 answer
  • Examples of email use that could be considered unethical include _____.
    14·2 answers
  • If you created a variable called name, what data type would that value be? Group of answer choices a float a string a Boolean an
    5·2 answers
  • ¿Qué son las tecnologías modernas?
    6·1 answer
  • Which of the following tabs on the Ribbon contains the command to add a Quick Part to a document? A Design B Insert C View D Hom
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!