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
frosja888 [35]
3 years ago
12

Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, a

nd swaps array elements at indices 2 and 3. Then write a main program that reads four integers from input and stores the integers in an array in positions 0 to 3. The main program should call function swapValues() to swap array's values and print the swapped values on a single line separated with spaces.
Computers and Technology
1 answer:
Luba_88 [7]3 years ago
6 0

The program is an illustration of arrays.

Arrays are used to hold multiple values.

The program in java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

   //This defines the method

public static int[] swapValues(int[] arr) {

   //This swaps the first and second array elements

       int temp = arr[0];

       arr[0] = arr[1];   arr[1] = temp;

   //This swaps the third and fourth array elements

       temp = arr[2];

       arr[2] = arr[3];   arr[3] = temp;

   //This returns the swapped array to main

       return arr;

}

//The main method begins here

   public static void main(String[] args) {

       //This creates a Scanner object

       Scanner input = new Scanner(System.in);

 //This declares an array of 4 elements

 int[] intArray = new int[4];

 //This gets input for the array

 for(int i = 0; i<4;i++){

     intArray[i] = input.nextInt();

 }

 //This calls the swapValues method

 intArray=swapValues(intArray);

 //This prints the swapped array

 for (int i = 0; i < 4; i++){

 System.out.print( intArray[i]+ " ");     }

}  

}

At the end of the program, the elements are swapped and printed.

Read more about similar programs at:

brainly.com/question/14017034

You might be interested in
What is the legal right granted to all authors and artists that gives them sole ownership and use of their words, software, pict
ICE Princess25 [194]

Answer:

copyright

Explanation:

3 0
4 years ago
What can I do If my Texas Instrument TI-84 calculator is not giving accurate answers?
zlopas [31]

Answer:

replace the batteries possibly

Explanation:

4 0
2 years ago
WILL GIVE BRAINLIEST ANSWER!!!<br><br> How do you manage your screen time?
Aloiza [94]
You can set it up in settings and set strict hours for screen time.
7 0
3 years ago
Read 2 more answers
HELP PLEASE!!! Which development method is best explained in this way: a creation of a prototype model that will eventually be d
DerKrebs [107]

Answer:

Not sure but I think its Rapid Prototyping Method

4 0
3 years ago
Which feature is needed to make enterprise application migrate to private cloud ?
den301095 [7]

The answer is C: Enablement of application as SaaS.

A cloud can provide IT infrastructure network services like storage and servers. Once an application has been identified as a potential candidate for cloud migration, it is important to consider what type of cloud environment; PaaS, SaaS, or IaaS. In this case, SaaS will be considered. SaaS host business application and makes them available to clients online. It removes the need for enterprises to run applications on their own.

8 0
3 years ago
Read 2 more answers
Other questions:
  • When a vehicle strikes a pedestrian, it's most often during A. a period of darkness or low visibility B. the day when pedestrian
    10·2 answers
  • (Microsoft excel) The data selected to create a table must include
    6·2 answers
  • How many values will the user submit each time this form is used? Color: RedBlueGreen Quantity:
    10·1 answer
  • Write down the pseudo code of a program that calculates the Body Mass Index (BMI) of
    9·1 answer
  • Which table option enables you to combine the contents of several cells into one cell?
    9·2 answers
  • Which software would you use to create a print design?
    8·2 answers
  • Sally is editing her science report about living things. She needs to copy a paragraph from her original report. Order the steps
    8·1 answer
  • Write a python function average_sample_median(n,P), that return the average of 1000 samples of size n sampled from the distribut
    10·1 answer
  • Someone who wants to learn a skilled trade on the job should consider
    6·2 answers
  • What is the binary for O?​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!