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
Which function can you use to abbreviate the lengthy expression, A1+A2+A3+A3...+A19+A20?  MAX COUNT SUM ROUND
Naddika [18.5K]
Which function can you use to abbreviate the lengthy expression, A1+A2+A3+A3...+A19+A20? SUM
6 0
4 years ago
Read 2 more answers
REOLVER EL SIGUIENTE PROBLEMA: R1=1.7K, R2=33K R3=4.7K R4=5.9K R5=17K IT=20mA CALCULAR: VT, I1, I2, I3, I4, I5 Y RT
Aneli [31]
Answer :

Ok

Step-by-Step Explanation:
7 0
3 years ago
What is computer assisted translation​
Vlad1618 [11]

Answer:

the use of software to assist a human translator in the translation process.

Explanation:

8 0
3 years ago
If you don’t have a paper copy of the FAFSA form, how else can you fill it out?
Ronch [10]
Go on your school computer, and find a copy of the form. Then print it from the school printer.
3 0
3 years ago
Read 2 more answers
Edhesive Assignment 8: Personal Organizer.
Rudik [331]

In this exercise we have to use the knowledge in computational language in python to write the following code:

<h3>What is input?</h3>

Python's input function takes a single parameter which is a string. This string is often called a prompt because it contains informational text that tells the user to type something. For example, you can call the input function as follows:

So in an easier way we have that the code is:

<em>eventName = []</em>

<em>eventMonth = []</em>

<em>eventDay = []</em>

<em>eventYear = []</em>

<em>def addEvent():</em>

<em>userEventName = input("What is the event: ")</em>

<em>userEventMonth = int(input("What is the month (number): "))</em>

<em>userEventDay = int(input("What is the date: "))</em>

<em>userEventYear = int(input("What is the year: "))</em>

<em>userEventMonth = validateMonth(userEventMonth)</em>

<em>userEventDay = validateDay(userEventMonth, userEventDay, userEventYear)</em>

<em>eventName.append(userEventName)</em>

<em>eventMonth.append(userEventMonth)</em>

<em>eventDay.append(userEventDay)</em>

<em>eventYear.append(userEventYear)</em>

<em>def validateMonth(month):</em>

<em>if month >= 1 and month <= 12:</em>

<em>return month</em>

<em>else:</em>

<em>return 1</em>

<em>def validateDay(month,day,year):</em>

<em>if day < 1 or day > 31:</em>

<em>return 1</em>

<em>if month == 2:</em>

<em>isleap = False</em>

<em>if year%4 == 0:</em>

<em>if year%100 == 0:</em>

<em>if year%400 == 0:</em>

<em>isleap = True</em>

<em>else:</em>

<em>isleap = True</em>

<em>if isleap:</em>

<em>if day <30:</em>

<em>return day</em>

<em>else:</em>

<em>return 1</em>

<em>else:</em>

<em>if day < 29:</em>

<em>return day</em>

<em>else:</em>

<em>return 1</em>

<em>if month in [1,3,5,7,8,10,12]:</em>

<em>return day</em>

<em>if month in [4,6,9,11] and day < 31:</em>

<em>return day</em>

<em>else:</em>

<em>return 1</em>

<em>def printEvents():</em>

<em>print("EVENTS")</em>

<em>months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']</em>

<em>for index in range(len(eventName)):</em>

<em>print(eventName[index])</em>

<em>print("Date: "+months[eventMonth[index] -1]+ " " + str(eventDay[index]) + ", " + str(eventYear[index]))</em>

<em>userChoice = "yes"</em>

<em>while userChoice.upper() != "NO":</em>

<em>addEvent()</em>

<em>userChoice = input("Do you want to enter another event? NO to stop: ")</em>

<em>printEvents()</em>

See more about python at brainly.com/question/18502436

5 0
2 years ago
Other questions:
  • A group of researchers is designing an experiment to test whether meditation helps people fall asleep faster. The researchers se
    14·1 answer
  • an organization that maintains a gateway to the Internet and rents access to customers on a per-use of subscription basis\ and W
    11·1 answer
  • If a movie starts at 305 and the movie is 2 hrs and 44 mins when does the movie end?
    14·1 answer
  • _____ is the network protocol that deals with the routing of packets through interconnected networks to the final destination.
    9·1 answer
  • It is safe to stand on the top step of a ladder provided it is braced property
    10·1 answer
  • Pamela finds that she is constantly spelling the word “color” as “colour” when she is typing. Even though this is how the word i
    11·1 answer
  • 5.14 Describe how the compare and swap() instruction can be used to provide mutual exclusion that satisfies the bounded-waiting
    13·1 answer
  • PLEASE HELP ILL GIVE BRAINLIEST IMMEDIATLEY TO THE CORRECT ;-;
    10·1 answer
  • SOMEONE HELP ME PLEASE <br> What are three reasons technology is beneficial to teens
    11·1 answer
  • Which of these agents of education empowers the other..........
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!