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
Which of the following is the smallest aperture (f-stop) opening?
Firlakuza [10]

Answer:

E) f/16

Explanation:

6 0
3 years ago
The portion of memory that is more or less permanent is called __________ memory.
lisabon 2012 [21]

The portion of memory that is more or less permanent is called <u>long term memory.</u>

<u></u>

<h3>What is Long-term memory?</h3>

Long-term memory guides to the memory process in the brain that takes knowledge from the short-term memory store and creates long-lasting memories. These recollections can be from an hour ago or several decades ago. Long-term memory can hold an unlimited amount of knowledge for an indefinite period of time.

<h3>What is long-term memory in psychology?</h3>

Long-term memory refers to unlimited storage information to be carried for long periods, even for life. There are two types of long-term memory: declarative or direct memory and non-declarative or implicit memory. Direct memory refers to information that can be consciously evoked.

To learn more about Long-term memory, refer

brainly.com/question/25040884

#SPJ4

6 0
1 year ago
Write a c program to print all possible marking schemes of 15 questions each with 3.
andrey2020 [161]

Answer:

#include <math.h>

#include <stdio.h>

#include <string.h>

#define BASE 3

#define NRQUESTIONS 15

void toABC(int n, char* buf, int base, int size) {

   memset(buf, 'A', size);

   buf[size] = 0;

   while (n && size) {

       buf[--size] = 'A' + (n % base);

       n /= base;

   }    

}

int main()

{

   char buf[16];

   for (int i = 0; i < pow(BASE, NRQUESTIONS); i++) {

       toABC(i, buf, BASE, NRQUESTIONS);

       printf("%s\n", buf);

   }

}

Explanation:

Assuming 3 is the number of possible answers to choose from for each question.

I tackled this by having an integer counter enumerate all values from 0 to 3^15, and then convert each integer to a base-3 representation, using ABC in stead of 012.

3 0
2 years ago
Write a function named hasFinalLetter that takes two parameters
krek1111 [17]

Answer:

66

Explanation:

gfgrgdgghegdgdggdgdgd

4 0
2 years ago
If you want to refine your Google search results by date, which option should you use?
MatroZZZ [7]
On the latest updated version of google the tools option below you search will let you filter you search by time.
4 0
2 years ago
Other questions:
  • Which of the given original work is protected by the copyright law
    9·1 answer
  • Why are cable networks such as mtv and cnn more profitable than the big four broadcast networks?
    8·1 answer
  • Amy just added a 462 meter run of fiber optic cable to the network what should she do next?
    10·1 answer
  • 30points for help
    14·1 answer
  • What does the -pwd switch do? how can you make dsadd bring up a prompt asking for the users password?
    10·1 answer
  • Variable index has a value of 4, and variable accessValid has a value of False. What value does variable, accessPoints, have aft
    7·1 answer
  • Queries are questions true or false?
    9·1 answer
  • When an EC2 instance is being modified to have more RAM, is this considered Scaling Up or Scaling Out?
    5·1 answer
  • Which method adds 10 to the right end of the array?<br> myArray.<br> insert<br> (10)
    9·1 answer
  • What feature preserves your open apps and data, but allows another user to log in to his or her own session of the same computer
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!