🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.help
Article #18

swapping array elements

#18
From: John Fu
Date: Sun, 29 Oct 2000 07:13
28 lines
2079 bytes
I have a problem with my code. And I find that my swap method isn't really
swapping the elements declared in my arrays. Can someone help please.  I
know it's just something simple that I'm missing, but I just can't catch it.
Thanks.

import java.io.*;

public class test
{
     static int[] pos = new int[3];
     public static void main(String args[]) throws Exception
     {
          pos[0] = 1;
          pos[1] = 2;
          pos[2] = 3;
          swap(pos[0],pos[1]);
          System.out.println("pos[0] = "+pos[0]);
          System.out.println("pos[1] = "+pos[1]);
          System.out.println("pos[2] = "+pos[2]);
     }//end main
     public static void swap(int x, int y) throws Exception
     {
          int tmp;
          tmp = x;
          x = y;
          y = tmp;
     }//end swap
}
Technical Details
Message-ID: <8tgikk$gk6$1@bugstomper.ihug.com.au>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-01!supernews.com!newshub2.rdc1.sfba.home.com!news.home.com!cyclone-sjo1.usenetserver.com!news-out.usenetserver.com!HSNX.atgi.net!sjc-peer.news.verio.net!news.verio.net!nntp2.cerf.net!nntp3.cerf.net!ihug.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!news.tig.com.au!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,1141f690fb55e2e0,start
X-Google-Attributes: gid10d6db,public
X-Google-Thread: 113ae9,1141f690fb55e2e0,start
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,1141f690fb55e2e0,start
X-Google-Attributes: gid10a146,public
X-Google-ArrivalTime: 2000-10-29 00:12:21 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-01!supernews.com!newshub2.rdc1.sfba.home.com!news.home.com!cyclone-sjo1.usenetserver.com!news-out.usenetserver.com!HSNX.atgi.net!sjc-peer.news.verio.net!news.verio.net!nntp2.cerf.net!nntp3.cerf.net!ihug.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!news.tig.com.au!not-for-mail
From: "John Fu" <zenki@ihug.com.au>
Newsgroups: comp.lang.java.help,comp.lang.java.programmer,aus.computers.java
Subject: swapping array elements
Date: Sun, 29 Oct 2000 18:13:36 +1100
Organization: The Internet Group (Sydney)
Lines: 30
Message-ID: <8tgikk$gk6$1@bugstomper.ihug.com.au>
NNTP-Posting-Host: p89-tnt1.syd.ihug.com.au
X-Trace: bugstomper.ihug.com.au 972803540 17030 203.173.128.89 (29 Oct 2000 07:12:20 GMT)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400