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
How to check if students viewed an assignment canvas.
Greeley [361]
Which app are you using?
6 0
2 years ago
What does the hard disk drive do?
Airida [17]
It stores data and retrieving digital information using one or more rigid rapidly rotating disks (platters) coated in magnetic material
4 0
3 years ago
Read 2 more answers
Which of the following is not an ideal habitat for a strong time-management plan
Maurinko [17]
The answer to this question is, A. Cramming.


PLEASE MARK BRAINLIEST!! :)
5 0
3 years ago
Read 2 more answers
Programa que previene, detecta y elimina virus informáticos.
vesna_86 [32]

Answer:

Software antivirus

Explanation:

6 0
3 years ago
A credit card can be a good way to pay when yo can’t afford something for a very long time? True or false
scoray [572]
False. Credit cards usually have high interest rates if you don’t pay them off right away. The only way to benefit from a credit card is if you pay it off by the due date monthly.
7 0
2 years ago
Other questions:
  • Define the following term: - hue
    11·2 answers
  • I'm trying to connect fire stick but it doesn't have HDMI input so guys what would do you recommend to buy I tried a converter b
    8·1 answer
  • When the packet leaves the router, which source and destination ip addresses will be contained in the packet?
    9·1 answer
  • What are some options available when using the Replace feature?
    13·1 answer
  • How is the execution speed of machine language compared to that of high-level languages? The execution speed of machine language
    10·2 answers
  • You work in the Accounting department and have been using a network drive to post Excel workbook files to your file server as yo
    15·1 answer
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • Which hexadecimal number is equivalent to the decimal number 11?
    13·1 answer
  • . Let F(X, Y, Z)=(X + Y + Z)(X + Y + Z)(X + Y + Z)(X + Y + Z). Use a 3-variable K-Map to find the minimized SOP form of this fun
    15·1 answer
  • A seven-octet pattern of alternating 0s and 1s used by the receiver to establish bit synchronization is a _______
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!