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
Complete the sentence.
IgorC [24]
You would run it on a desktop, as they usually can process things much better.
4 0
3 years ago
Ted is asked to create a page of family photos for his family reunion Web site. He will have about 20 pictures to post, with a c
Alja [10]

Answer:

A

Explanation:

© is the symbol for copyright or Copr. for abbreviation.

7 0
4 years ago
2. What does the "Users" metric measure?
fredd [130]

Answer:

Users that had at least one session on your site in the given date range

Explanation:

UserMetrics is use to measure user activity based on a set of standardized metrics. Using user metrics, a set of key metrics can be selected and applied to a cohort of users to measure their overall productivity. User Metric is designed for extensibility (creating new metrics, modifying metric parameters) and to support various types of cohort analysis and program evaluation in a user-friendly way.

3 0
3 years ago
Programs which were typically reserved for college-level classes such as computer animation and CAD programs are now being appli
Irina-Kira [14]
Answer: I think C


Step by step explanation:
8 0
3 years ago
Which part of an I-statement involves a description of your needs or feelings? The part of an I-statement involves a description
MrMuchimi

The part of an I-statement that involves a description of

your needs or feelings is the Feelings Statement.



The feelings statement is a description of your feelings that is linked to a

particular situation. Vague feelings often create frustration in the listener.



6 0
3 years ago
Read 2 more answers
Other questions:
  • What is the legal right granted to all authors and artists that gives them sole ownership and use of their words, software, pict
    9·2 answers
  • What type of graphic organizer will help jane compare the results of a student survey about teachers at her school?
    15·2 answers
  • Based on your learning this week, consider rules, policies, and procedures. Technicians are often eager to just get started on a
    10·1 answer
  • Isaac was assigned to work on a computer in his company’s R&amp;D department. While working on the system, Isaac received severa
    8·1 answer
  • In a stream channel what is deposited first?
    7·1 answer
  • You use a 1200 watt hair dryer for 10 mintues a day.
    7·1 answer
  • Jim lost his job due to the replacement of robots in a manufacturing factory. As an ethical practice, what should the manufactur
    13·1 answer
  • Many companies ban or restrict the use of flash drives
    11·1 answer
  • What should be entered to make the loop print
    6·1 answer
  • Does anyone know what's wrong with this code in Unity? HELP FAST PLEASE! This is for my game design course, I will give brainies
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!