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
The User Datagram Protocol (UDP) is called the connectionless protocol because: It does not attempt to fix bad packets but resen
DochEvi [55]

Answer:

The User Datagram Protocol (UDP) is called the connectionless protocol because:

It does not attempt to fix bad packets or resend lost packets.

Explanation:

Ports are openings or entrance doors through which data packages have access to a PC or server.  TCP and UDP are transport protocols with port numbers.  TCP means Transmission Control Protocol.  They are used to connect two devices over the internet and other networks.  UDP means User Datagram Protocol.  They are used to connect applications and to speed the transfer of data.  Comparatively, UDP is faster, simpler, and more efficient than TCP.  TCP enables retransmission of lost data packets, which UDP cannot do.

4 0
2 years ago
List 100 social media with functions​
olga55 [171]

Answer:

J

Explanation:

6 0
2 years ago
Convert 1/32 GB into MB​
kiruha [24]

Answer:

31.25 megabytes.

31.25 megabytes

7 0
2 years ago
what is the worst-case big o running time for finding the maximum value in an array of size n by scanning from left to right and
Aleksandr-060686 [28]

Answer:

spanish

Explanation:

no ingles a me pisquen spanish soy tu amigos teacher

6 0
1 year ago
Write a program that asks the user for the name of a text file. the program should display the last 10 lines of the file on the
Tom [10]
The only thing that I know is that after you input the text file, it could either:
-save those lines as a variable
-display the text file
However any more would be dependent on the language.
3 0
3 years ago
Other questions:
  • There are ways to perform computer commands quickly and multiple times. <br> a. True <br> b. False
    11·2 answers
  • Which wireless communication technology is most likely used when synchronizing device information to an automobile?
    14·1 answer
  • Why did latex replace wax?
    7·1 answer
  • What does the Finder do?
    7·1 answer
  • Determine the number of cache sets (S), tag bits (t), set index bits (s), and block offset bits (b) for a 40964096-byte cache us
    15·1 answer
  • What is a computer dedicated to a single function, such as a calculator or computer game? A. TabletB. PDAC.ApplianceD. Minicompu
    6·1 answer
  • One blog may have a greater social influence than another when it has_______?
    12·2 answers
  • 3.26 LAB: Leap Year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate a
    15·2 answers
  • A rectangle indicates a single process.true or false​
    7·2 answers
  • The function's only behavior should be to return the sum of array userVals' elements. What common error does the function make?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!