Array help, New to Java.

Discussion in 'Java' started by PreetiSweet, Apr 4, 2011.

  1. PreetiSweet

    PreetiSweet

    Joined:
    Apr 4, 2011
    Messages:
    1
    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;
    }
    }
     
    PreetiSweet, Apr 4, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NANY(kshore)
    Replies:
    2
    Views:
    323
  2. [rob desbois]
    Replies:
    2
    Views:
    283
    [rob desbois]
    Apr 15, 2008
  3. sonic
    Replies:
    5
    Views:
    94
  4. weblinkunlimited@gmail.com

    Javascript new-new-new-new-newbee

    weblinkunlimited@gmail.com, Mar 10, 2008, in forum: Javascript
    Replies:
    2
    Views:
    468
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
  5. Xu, Qian
    Replies:
    2
    Views:
    81
Loading...

Share This Page