- Joined
- Apr 4, 2011
- Messages
- 1
- Reaction score
- 0
For my Java 101 class we have to get the two numbers to 'swap', this is what my professor gave us and he says that we need to fix the array to get the output to swap.
Right now it just outputs the same thing twice, I can't figure out the new array.
Help meee, please and thanks.
public class cw328swap {
public static void main(String[] args) {
int [] a = {1,2};
System.out.println(a[0] + " g " + a[1]);
swap(a[0], a[1]);
System.out.println(a[0] + " g " + a[1]);
}
public static void swap (int n1, int n2) {
int temp=n1;
n1=n2;
n2=temp;
}
}
Right now it just outputs the same thing twice, I can't figure out the new array.
Help meee, please and thanks.
public class cw328swap {
public static void main(String[] args) {
int [] a = {1,2};
System.out.println(a[0] + " g " + a[1]);
swap(a[0], a[1]);
System.out.println(a[0] + " g " + a[1]);
}
public static void swap (int n1, int n2) {
int temp=n1;
n1=n2;
n2=temp;
}
}