Array help, New to Java.

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top