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]
4 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]4 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]4 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
can you imagine what life might have been like before the internet laptops and smartphones were part of everyday life what are s
svet-max [94.6K]

Answer:

no

Explanation:

it does not matches me

7 0
3 years ago
Read 2 more answers
Which fonts do not have a practical use in writing
kondaur [170]
To be honest with you, I don’t know but you can always look up on google “which fonts do not have a practical use in writing” and then there are links you can look up for the answer . Sorry but I don’t know which link is the best answer for your question ;) have a great day bro
8 0
3 years ago
Is windows CUI operating system??<br><br><br>What is the main purpose of folder ????<br><br><br>​
Likurg_2 [28]
Answer: yes and main purpose of folder can help in storing and organizing files and data in the computer.

Hope this helped!
8 0
3 years ago
What is the role of a Chief Information Officier in anorganization?
vladimir1956 [14]

Answer and Explanation:

There are several roles of a Chief Information Officer in any organization and these are as follows:

  • He must fulfill his responsibility as a business leader.
  • He must be able to make executive decisions regarding sales and purchase related matters.
  • He must be able to deal with all the Information Technology related problems.
  • He must be able to recruit the best candidates in the best interest of the organization.
  • He is required to map out the ICT policy(includes procurement, external and internal standards of an organization, future proofing) and ICT strategy.
  • He must be able to write up ICT policy  with detail of its utilization and application.
  • He must possess organizational skills

8 0
3 years ago
A ______ object is used for displaying the results of a question based on stored data.
LekaFEV [45]

Answer:

B. report

Explanation:

Report is used to show the result of data base quires or stored data contain useful data use in decision making and analysis.

It is also called a report generator, it is a part of database management system that is used to extract information from one or more files and present it in specific format.

4 0
3 years ago
Other questions:
  • A _____ is a search engine that combines internet technology with traditional library methods of cataloguing and assessing data.
    8·1 answer
  • When you buy an Xbox 360 can you play online for free
    12·2 answers
  • Successful Web sites such as StumbleUpon ( www.stumbleupon) and Digg ( www.digg) use ____ by inviting their visitors to vote on
    8·1 answer
  • Convert 1001101012 to base 10
    5·1 answer
  • When each line of text hits the margin at the same point what is the text?
    8·1 answer
  • How do I change my name on my Brainly Profile?
    15·2 answers
  • A heart murmur is caused by incorrect operation of ________?​
    7·1 answer
  • Ten ways ict has helped in social development
    7·1 answer
  • Project: Design and Development Research Project
    14·1 answer
  • What is the difference between encoding and decoding?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!