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
In-s [12.5K]
3 years ago
12

Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 then the outp

ut is: 8 3 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVal1, int* userVal2)
Computers and Technology
1 answer:
Ainat [17]3 years ago
4 0

Answer:

public class num3 {

   public static String swapValues(int userVal1, int userVal2){

       int temp = userVal2;

       userVal2 = userVal1;

       userVal1 = temp;

       return(userVal1+", "+userVal2);

   }

   public static void main(String[] args) {

       int val1 = 5;

       int val2 = 8;

       System.out.println("Original values");

       System.out.println(val1+", "+val2);

       System.out.println("Swapped Values");

       System.out.println(swapValues(val1,val2));

   }

}

Explanation:

  • The problem is solved with Java programming language
  • Define the method swapValues() to accept two ints and return a String
  • Within the method body, create a temp variable to hold the value of userVal2 temporary
  • Do the following re-assignment of values userVal2 = userVal1; userVal1 = temp;
  • Return the concatenated String userVal1+", "+userVal2
  • Create two variables and initialize them in the main method
  • Output their values
  • Call swapValues() aand output the swapped values
You might be interested in
What is a Type 10 SD card?
Semmy [17]

Answer: Class 10 refers to the read write speed of a memory card

Explanation:

5 0
1 year ago
Osha requires employers pay for most required personal protective equipment including
zzz [600]
*Metatarsal foot protection
*Rubber boots with steel toes
*Non-prescription eye protection
*Prescription eyewear inserts/lenses for
full face respirators
*Goggles and face shields
*Fire fighting PPE (helmet, gloves, boots,
proximity suits, full gear)
*Hard hats
*Hearing protection
*Welding PPE
7 0
3 years ago
GPS consists of three segments. What are these segments?
lawyer [7]

Answer the answer is he Global Positioning System (GPS) is a U.S.-owned utility that provides users with positioning, navigation, and timing (PNT) services. This system consists of three segments: the space segment, the control segment, and the user segment. The U.S. Space Force develops, maintains, and operates the space and control segments.

Explanation:

7 0
2 years ago
Which of the following would NOT be considered an agricultural pest?
Komok [63]
A dog laying amongst the crops would not be a pest, so the correct choice would be the first one.
4 0
3 years ago
Read 2 more answers
Ergonomics is defined as
Scrat [10]

Answer:

B. The design and arrangement of items for efficiency and safety.  

Explanation:

6 0
3 years ago
Other questions:
  • Which of the following typically have the highest auto insurance premiums?
    14·1 answer
  • Who was the first person to make a portable computer?
    5·1 answer
  • This program will get you used to retrieving a value from a function. The function should be named getRandomNumber. The function
    15·1 answer
  • When activated, an Excel object has all the features of an Excel
    8·2 answers
  • Who were called “freedmen” during the reconstruction period?
    15·2 answers
  • One acre of Land is equivalent to 43,560 square feet. Write a program that ask the user to enter the total square feet of a piec
    5·1 answer
  • First Person Who Answers Fast As Possible Will Be Marked As Brainiest ​
    12·1 answer
  • Plssssssssssssss help quick
    8·1 answer
  • You plan on using cost based pricing. The cost of your product is 10, and you are planning a 30% mark up. What should the price
    14·1 answer
  • Cathy designed a website for a cereal brand. When users view the website, their eyes first fall on the brand name, then they vie
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!