82 266
Assignments Done
98,6%
Successfully Done
In January 2020

# Answer to Question #15718 in Java | JSP | JSF for Nicholai

Question #15718
Define a class called &lsquo;twoInt&rsquo; with two public integer fields a and b In the constructor of &lsquo;twoInt&rsquo;, initialize the a and b to be 1 and 2 Create an instance &lsquo;mytwoInt&rsquo; in the main method Write a method &lsquo;swap&rsquo; (not the method of the class &lsquo;twoInt&rsquo;) and pass the above instance &lsquo;mytwoInt&rsquo; into the method, swap two a and b in the method Print out a and b in the main method System.out.print(object.a + &lsquo; &lsquo; + object.b); Swap(object); System.out.print(object.a + &lsquo; &lsquo; + object.b); my code public class TwoInt { public static void main (String [] args) { int a; int b; TwoInt myTwoInt = new TwoInt(); System.out.println(myTwoInt.a + &quot; &quot; + myTwoInt.b); } public TwoInt() { a = 1; b = 2; } public void swap (myTwoInt int a, int b) { int tmp = a; a = b; b = tmp; System.out.println(myTwoInt.a + &quot; &quot; + myTwoInt.b); }
1
2012-10-02T07:20:57-0400
public class twoIntTest {

/**
& * @param args
& */
public static void main(String[] args) {
& TwoInt object = new TwoInt();
& System.out.println(object.a + &quot; &quot; + object.b);
& swap(object);
& System.out.println(object.a + &quot; &quot; + object.b);
}

public static void swap(TwoInt object) {
& int temp = object.a;
& object.a = object.b;
& object.b = temp;
}
}

class TwoInt {
public TwoInt() {
& a = 1;
& b = 2;
}

public int a;
public int b;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!