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
Nimfa-mama [501]
3 years ago
14

Write two public static methods in the U6_L4_Activity_Two class. The first should have the signature swap(int[] arr, int i, int

j) and return type void. This method should swap the values at the indices i and j of the array arr (precondition: i and j are both valid indices for arr). The second method should have the signature allSwap(int[] arr) and return type void. The precondition for this method is that arr has an even length. The method should swap the values of all adjacent pairs of elements in the array, so that for example the array {3, 5, 2, 1, 8, 10} becomes {5, 3, 1, 2, 10, 8} after this method is called.
Computers and Technology
1 answer:
Tems11 [23]3 years ago
4 0

Answer:

public static void swap(int[] arr, int i, int j) {

   if(i >=0 && i <=arr.length-1 && j >=0 && j<=arr.length-1){

       int hold = arr[i];

       arr[i] = arr[j];

       arr[j] = hold;

   }

}

public static void allSwap(int[] arr) {

   if (arr.length % 2 == 0){

       for(int i=0; i<arr.length; i+=2){

           int hold = arr[i+1];

           arr[i+1] = arr[i];

           arr[i] = hold;

       }

   } else{

       System.out.println("array length is not even.");

   }

}

Explanation:

The two functions, swap and allSwap are defined methods in a class. The latter swaps the item values at the specified index in an array while the second accepts an array of even length and swap the adjacent values.

You might be interested in
How are engineers are related to technology
vichka [17]
Engineering is the application of knowledge and technology is the body of knowledge:)
4 0
3 years ago
Why is IP configuration used with its components for network, broadcast, host addresses, and local host?
matrenka [14]

Answer:

GeoLocation

Explanation:

It is based on geolocation and wireless provider so it differs based on where and what hope this helps!

3 0
3 years ago
A company decides to create static design diagrams for an upcoming project. Which statement correctly describes the attribute of
kotykmax [81]

Answer:

A

Explanation:

4 0
3 years ago
What is the function of an ISP,a browser and a mobile browser?​
ruslelena [56]

An internet service provider (ISP) is a company that provides web access to both businesses and consumers. ISPs may also provide other services such as email services, domain registration, web hosting, and browser services.

The purpose of a web browser is to fetch information resources from the Web and display them on a user's device. This process begins when the user inputs a Uniform Resource Locator (URL), such as wikipedia.org, into the browser.

A mobile browser is a web browser designed for use on a mobile device such as a mobile phone or PDA. Mobile browsers are optimized to display Web content most effectively for small screens on portable devices.

8 0
3 years ago
Write an application that allows a user to select a country from a list box that contains the following seven options. After the
hodyreva [135]

Answer:

Programming Language not stated;

But this application definitely requires a graphical user interface platform (so, I'll use Microsoft Visual C# - Winforms).

Controls to be used are.

1. Form

2. List box

I'll name the Form, Form1 and the list box, listbox1.

Explanation:

The code goes thus;

private void Form1_Load(object sender, System.EventArgs e)

{

//Load country into empty listbox

listbox1.Items.Add("Austria");

listbox1.Items.Add("Canada");

listbox1.Items.Add("England");

listbox1.Items.Add("France");

listbox1.Items.Add("Italy");

listbox1.Items.Add("Mexico");

listbox1.Items.Add("Spain");

}

private void listbox1_SelectedIndexChanged(object sender, System.EventArgs e)

{

//Check if an item is really selected

if(listbox1.SelectedIndex >= 0)

{

//Index 0 represents 1st item that was added to the listbox and that's Austria

if(listbox1.SelectedIndex ==0)

{

MessageBox.Show("Vienna");

}

else if(listbox1.SelectedIndex == 1)

{

MessageBox.Show("Toronto");

}

else if(listbox1.SelectedIndex ==2)

{

MessageBox.Show("London");

}

else if(listbox1.SelectedIndex == 3)

{

MessageBox.Show("Paris");

}

else if(listbox1.SelectedIndex ==4)

{

MessageBox.Show("Rome");

}

else if(listbox1.SelectedIndex == 5)

{

MessageBox.Show("Mexico City");

}

else if(listbox1.SelectedIndex == 6)

{

MessageBox.Show("Madrid");

}

}

else

{

MessageBox.Show("No item selected");

}

}

6 0
3 years ago
Other questions:
  • Using a loop, write a program that reads in exactly five integers and outputs the sum.
    11·1 answer
  • Which of the following is NOT true of input validation?
    7·1 answer
  • A proactive computer professional will _____. have a neutral outlook toward technology underestimate the impact of technology an
    13·2 answers
  • After a conditional formatting rule is created using the ____ dialog box, the rule is then available for use in the database fro
    11·1 answer
  • A technician suspects a network card is not working. Which tool should the technician use to test the network card?
    8·1 answer
  • A computer essentially takes input, processes it, and produces output. Which person developed a machine in the mid-1880s that ac
    6·1 answer
  • The __________ on a mouse is used to select or place the cursor where you want on the page
    13·1 answer
  • Body positioning is an example of what type of communication?
    6·1 answer
  • Slide rule was an analog device invented by William oughtred in 1620 it is true or false​
    14·1 answer
  • Which code snippet is the correct way to rewrite this in Semantic HTML?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!