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
vladimir2022 [97]
3 years ago
5

Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} b

ecomes {40, 20, 30, 10}.

Computers and Technology
2 answers:
grandymaker [24]3 years ago
8 0

Answer:

Python method swapArrayEnds()

def swapArrayEnds(array):      

   size = len(array)  

   temp = array[0]  

   array[0] = array[size - 1]  

   array[size - 1] = temp  

   return array

         

Explanation:

You can call the method in main program to swap the first and last elements of sortArray as following:

def swapArrayEnds(array):

   size = len(array)  

   temp = array[0]  

   array[0] = array[size - 1]  

   array[size - 1] = temp  

   return array  

     

sortArray = [10, 20, 30, 40]  

 

print(swapArrayEnds(sortArray))

This function works as following:

size stores the length of the array.

temp is a temporary variable that holds the first element of the array

The it swaps the first element of the array with the last element using this statement: array[0] = array[size - 1]  where size-1 contains the last element.

It finally stores the last element of the array in temp and returns the array after this swapping is done.

Then in the main program an array sortArray is given the values 10,20,30,40 and then the method swapArrayEnds()  is called to swap the first and last elements of sortArray.

The complete program with the output is attached in a screenshot.

dybincka [34]3 years ago
4 0

Answer:

The solution code is written in Java.

  1.    public static void swapArrayEnds(int myArray[]){
  2.        int lastIndex = myArray.length-1;
  3.        int temp = myArray[0];
  4.        myArray[0] = myArray[lastIndex];
  5.        myArray[lastIndex ] = temp;
  6.    }

Explanation:

First create the swapArrayEngs method that take one input array parameter (Line 1).

Since we need to swap the first and last element of the array, we need to get the first index and last index of the array. The first index is 0 and the last index can be calculated by subtracting the length of array from 1 (Line 2).

Next, we can create a temp variable to hold the value of the first element (Line 3). Then we use the lastIndex the get the value of last element and assign it to the first element of array (Line 4). Lastly, we assign the temp (holding the  initial first element value) to the last element of array (Line 5).

 

You might be interested in
John has had a message pop-up on his computer asking him to pay $800 to have his files
faltersainse [42]

• Installed a program containing ransomware/malware. (Do not accept downloaded without inferring it was installed)

• Opened an email attachment containing malware.

• Opened a file containing a malicious macro.

• Left his computer unsecure allowing someone else to install malware on it. (Should include an example, e.g. not logging off)

3 0
3 years ago
Read 2 more answers
What is used to switch to Outline View?
Yuri [45]
<span>What is used to switch to Outline View?

the Insert tab
the status bar
the Mailings tab
the Page Layout bar</span>

Actually, it is found in the VIEW TAB which is in the STATUS BAR. Coincidentally, all of those tabs can be found in the status bar.

7 0
3 years ago
Read 2 more answers
Create a new method in your language called Times Print. This should be a void method. It should accept exactly two numeric valu
user100 [1]

Answer:

The code commented is given below, also the lines that start with # are comments that explains the code.

# Create a function named times_print that receives 2 values x and y

def times_print(x, y):

   # Print the formatted string

   print("The value of {} times {} is {}".format(x,y,x*y))

# Create the main function

def main():

   # Call the funciton times_print 3 times with different values

   times_print(2,3)

   times_print(4,5)

   times_print(5,6)

# Execute the main function

main()

Explanation:

The code was written using Python 3.5, and here I attach the screenshots of the program running:

8 0
4 years ago
Select the correct answer. Richard wants to use a technology that allows the automation of manufacturing cars in his factory. Wh
Gemiola [76]

CAM C. rapid prototyping is the correct option for Richard wants to use a technology that allows the automation of manufacturing cars in his factory.

<h3>What is prototyping?</h3>

Prototyping is an iterative process in which design teams translate abstract ideas into tangible forms, which might range from paper to digital.

To capture design concepts and test them on people, teams create prototypes of varied degrees of quality. one can modify and validate designs with prototypes.

Thus, option B is correct.

For more details about prototyping, click here

brainly.com/question/24231598

#SPJ1

6 0
2 years ago
Read 2 more answers
At the county fair, prizes are awat rded to the five heaviest cows. More than 2000 cows are entered, and their records are store
Sergeu [11.5K]

Answer:

B

Explanation:

selection sort for each pass sorts one element in right place . so we can stop it after 5 passes as we need only 5 heaviest cows info.

Answer is B

6 0
3 years ago
Other questions:
  • How to change my ip address
    8·2 answers
  • Which of the following matching is true concerning the Protocol Data Unit (PDU) and its corresponding OSI layer location?
    15·1 answer
  • What is the very first thing a user usually must do to gain access to a secure computer?
    7·1 answer
  • Which part of a formal email is optional
    6·2 answers
  • When you tell an acquaintance your telephone number, you do not recite the digits one by one at a constant rate, as in "3, 3, 7,
    11·1 answer
  • What are three ways you cite evedince
    5·2 answers
  • Given the following function definition, what modifications need to be made to the search function so that it finds all occurren
    7·1 answer
  • A user has just reported that he downloaded a file from a prospective client using IM. The user indicates that the file was call
    11·1 answer
  • What is the reason of non-deterministic (indeterminate) behavior of concurrent programs?
    9·1 answer
  • Which of the following is the BEST reason to use cash for making purchases? everfi
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!