Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Array help, New to Java.

Reply
Thread Tools

Array help, New to Java.

 
 
PreetiSweet PreetiSweet is offline
Junior Member
Join Date: Apr 2011
Posts: 1
 
      04-03-2011
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;
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Javascript new-new-new-new-newbee weblinkunlimited@gmail.com Javascript 2 03-11-2008 01:15 AM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
declaring an array with "new Array()" vs "[]" sonic Javascript 5 07-12-2005 03:45 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments