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
Assume that you have an ArrayList variable named a containing 4 elements, and an object named element that is the correct type t
jonny [76]

Answer:

Option (4) is the correct answer.

Explanation:

In Java programming language ,array collection starts from 0 index location and ends in a size-1 index location. So to access the last elements the user needs to use a[Size-1] statement. so to modify the value of the last location of the array the user needs to use "a[size-1]= element;".

But when the user wants to add some new value to the end of the array list collection then he needs to use the statement--

a.add(element); //where add is a function, element is a value and a is a array list object.

Another option is invalid because--

  • Option 1 is not the correct because "a[3]=element;" modify the value of the 3rd element of the array.
  • Option 2 gives a compile-time error because add functions bracts are not closed.
  • Option 3 gives the error because a[4] gives the location of the 5th element of the array but the above question says that a is defined with 4 elements.
7 0
2 years ago
Please help me I don’t know what I’m doing wrong.
Alinara [238K]

Answer:

Explanation:

I noticed the \n, \n will cause the new line break, delete it.

try code below:

<em>System.out.println(" " + " " + "NO PARKING");</em>

<em>System.out.println("2:00 - 6:00 a.m.");</em>

5 0
2 years ago
____ is a technology that exists inside another device
Julli [10]

Answer:

Embedded technology is a technology that exists inside another device.

8 0
3 years ago
Read 2 more answers
Which of the following are responsibilities of information security management? Defining the protection required for systems and
Talja [164]

Answer:

all of them are responsibilities

Explanation:

4 0
2 years ago
Yan wants to attract customers specifically searching on Google for Time-B-Gone, his company's unique office-support product. Hi
Alecsey [184]

Answer:

The answer is "Option A".

Explanation:

The dynamic search ads also known as interactive contextual ads, that utilizes google advanced website browsing technologies to dynamically address relevant results requests based on the quality of a chain's website. These ads are beneficial for strategies, and other choices were wrong which can be described as follows:

  • In option B, It helps to upload all the dynamic search ads URLs quickly.
  • In option C, It helps to control computer service.
  • In option D, It increases the network traffic.
6 0
3 years ago
Other questions:
  • What is the pen tools use in Photoshop?
    6·2 answers
  • Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
    7·2 answers
  • A technician is configuring a new SOHO multifunction wireless router at a customer's location to provide network access to sever
    7·1 answer
  • When a computer is booted the checks the computer's components?
    7·1 answer
  • You have to calculate the total amount you spent at the mall today. Which function should you use to do so?
    6·2 answers
  • Why is it important to have at least one backup stored off-site?
    8·1 answer
  • A national tax preparation firm is accessing industry-specific productivity applications in the cloud; many other tax preparatio
    13·1 answer
  • What is drop shipping and how it works on amazon?
    12·1 answer
  • Assume there are two variables, k and m, each already associated with a positive integer value and further assume that k's value
    13·1 answer
  • What study skill is being used when taking a large project and breaking it down into smaller manageable tasks?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!