The int variables iA and iB contain values. Write a segment of Java code that wi
ID: 3628520 • Letter: T
Question
The int variables iA and iB contain values.Write a segment of Java code that will interchange these values
so that iA will now contain the value
that iB previously contained,
and iB will now contain the value that iA previously contained.
For example, if iA was equal to 6 initially, and iB was equal to 25,
then after your code executes, iA should be equal to 25
and iB should be equal to 6.
Note: This is only an example. Your code must be general,
that is, it must work correctly for ANY initial values of iA and iB,
not just 6 and 25.
You may define any new variables that you need.
You may find it useful to define a temporary int variable iTemp.
-This is pretty basic CS ( class 100) and I'm not sure what it's exactly asking for. A thorough solve would be great!
Explanation / Answer
please rate - thanks
public class Main
{public static void main(String[] args)
{int ia=5,ib=7,t;
t=ia;
ia=ib;
ib=t;
System.out.println("a="+ia+" b="+ib);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.