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
Suppose that the tuition for a university is $10,000 this year and increases 4% every year. In one year, the tuition will be $10
seropon [69]

Answer:

<em>The programming language is not stated; however, I'll answer using Python programming language (</em><em>Se</em><em>e attachment</em><em> </em><em>for</em><em> </em><em>proper </em><em>for</em><em>mat</em><em>)</em>

tuition = 10000

rate = 0.04

for i in range(1,15):

tuition = tuition + tuition * rate

if i <= 10:

print("Year "+str(i)+" tuition:",end=" ")

print(round(tuition,2))

if i == 14:

print("Tuition 4th year after:",end=" ")

print(round(tuition,2))

Explanation:

<em>The first 2 lines initializes tuition and rate to 10000 and 0.04 respectively</em>

tuition = 10000

rate = 0.04

<em>The next line iterates from year 1 to year 14</em>

for i in range(1,15):

<em>This line calculates the tuition for each year</em>

tuition = tuition + tuition * rate

<em>The next 3 lines prints the tuition for year 1 to year 10</em>

if i <= 10:

print("Year "+str(i)+" tuition:",end=" ")

print(round(tuition,2))

<em>The next 3 lines prints the tuition at the 4th year after year 10 (i.e. year 14)</em>

if i == 14:

print("Tuition 4th year after:",end=" ")

print(round(tuition,2))

7 0
3 years ago
What is the google search operator that limits results to a specific domain?
IrinaK [193]

Answer:

 Google search operator is also known as advanced operator which extend the various capabilities of the regular type of text searches. It basically contain various types of special characters and the commands.

Google search operator are very useful in the various technical and the content searches. This type of search operator also limits the result in the sites which are indexed with a specific domain and URL (User resource locator). The google search basically allow to use various symbols that are based on the operator.  

7 0
3 years ago
Only one person can receive the same email at the same time true or false
nasty-shy [4]

Answer:

false

Explanation:

5 0
3 years ago
Power point 2016 which chart element provides the boundaries of the graphic?
SVEN [57.7K]
D. (chart elemments) - correct answer
8 0
3 years ago
A(n) __________ is a popular way to describe relationships? (i.e., one-to-one,? one-to-many) in a relational database.
Leto [7]
A link is a popular way to describe relationships in a relational database.
There are three types of relationships (links) between tables:
1. One-to-one <span>relationship , that allows only one record on each side of the relationship.
2. </span>One-to-many <span>relationship, that allows a single record in one table to be related to multiple records in another table.
3. </span>Many-to-many<span> relationship, in which many records in a table can link to many records in another table. F</span>
6 0
3 years ago
Other questions:
  • Which of the following decimal (base-10) values is equivalent to the binary (base-2) value 101001?
    15·1 answer
  • In this exercise we examine in detail how an instruction is executed in a single-cycle datapath. Problems in this exercise refer
    6·1 answer
  • Tanya has received an email, apparently from her bank, stating that some of her records were lost during server maintenance work
    13·2 answers
  • You can apply several different worksheet themes from which tab?
    11·2 answers
  • If you wanted to search for emails containing the word advanced and prevent emails containing the word new from appearing in the
    14·1 answer
  • Interactive sites where users write personal topics and comments to a threadded discussion are called?
    11·1 answer
  • Anybody know this question??
    8·1 answer
  • The security administrator for Corp.com wants to provide wireless access for employees as well as guests. Multiple wireless acce
    11·1 answer
  • How to fix a light blub
    11·2 answers
  • What is the difference between HTML and XML?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!