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
You want to find the distance between two points.
maks197457 [2]

Answer:

For the first picture, choose the second pair, and for the second one, choose the first pair

Explanation:

5 0
3 years ago
What did the strict study generally find about the effect of internet use on sleep?
rjkz [21]
A. should be the answer hope this helps :)
4 0
3 years ago
Read 2 more answers
Hope has now created her sublist. 1. Oxygen a. Helps living things produce energy b. Helps protect living things from harmful ra
Alex_Xolod [135]

Answer: 1. put her insertion point at the end of item 2b. 2. press enter key

5 0
3 years ago
Describe how a black and white image could be represented in binary
SIZIF [17.4K]

Answer:

Each pixel in an image is made up of binary numbers. If we say that 1 is black (or on) and 0 is white (or off), then a simple black and white picture can be created using binary. To create the picture, a grid can be set out and the squares coloured (1 – black and 0 – white).

5 0
3 years ago
Read 2 more answers
Assume your sketch has a variable named silo, which stores an object that is defined by a class you have created. The name of th
yulyashka [42]

Answer:

c. let v = silo.volume();

Explanation:

When you create and initialize a new object you pass through that object's class constructor. The constructor is in charge of initializing all the necessary variables for that class including radius and height. Once you save the object in a specific variable (silo) you need to call the class methods through that variable, using the '.' command. Therefore, in this scenario, in order to call the volume() method you would need to call it from the silo object and save it to the v variable, using the following statement.

let v = silo.volume();

7 0
2 years ago
Other questions:
  • Henry uploaded the photos of his birthday to a cloud storage system. He feels that it’s a safe option for data storage. His frie
    12·1 answer
  • An anthropologist may try to learn why and how a culture develops.<br><br> A.true<br> B.false
    13·1 answer
  • Plz answer me will mark as brainliest picture included ​
    15·1 answer
  • What is the subnet mask ?
    9·2 answers
  • After a chart has been inserted and formatted, is it possible to change the data range it refers to or to add new rows of data?
    14·1 answer
  • You have noticed that one of your DNS servers has possibly been compromised. You believe that a cached DNS entry for your domain
    8·1 answer
  • The process known as "bitmapping" is defined as information in _____. PLEASE HELP FAST
    11·1 answer
  • L00000000000000000000000000000000000000000000000000000000l they b00ty tickled
    6·2 answers
  • The local library dealing with a major computer virus checked its computers and found several unauthorized programs, also known
    12·2 answers
  • The Texas Department of Education has offices throughout the state covering more than 268,000 square miles. State documents are
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!