.13 Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, and 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. Ex: If the input is: 3 8 2 4 function swapValues() returns and the main program outputs: 8 3 4 2 The program must define and call a method: public static void swapValues(int[] values) code:
18.13
Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, and 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.
Ex: If the input is:
3 8 2 4
function swapValues() returns and the main program outputs:
8 3 4 2
The program must define and call a method:
public static void swapValues(int[] values)
code:
import java.util.Scanner;
public class LabProgram {
/* Define your method here */
public static void main(String[] args) {
/* Type your code here. */
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images