🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: swapping array elements

#20
From: Deepak Grewal
Date: Mon, 13 Nov 2000 00:00
41 lines
2214 bytes
hi
  i m kinda new to java so maybe this isnt the best advice but u can still
try....
 when u call the method swap.... shouldnt u be saying this.swap
instead......??
 as the swap method is in the same class.............
tell me if it did or didnt work........

John Fu <zenki@ihug.com.au> wrote in message
news:8tgikk$gk6$1@bugstomper.ihug.com.au...
> 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: <3a0fe06c@news1.idx.com.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8tgikk$gk6$1@bugstomper.ihug.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,1141f690fb55e2e0
X-Google-Attributes: gid10d6db,public
X-Google-Thread: 113ae9,1141f690fb55e2e0
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,1141f690fb55e2e0
X-Google-Attributes: gid10a146,public
From: "Deepak Grewal" <deepakgrewal@rediffmail.com>
Subject: Re: swapping array elements
Date: 2000/11/13
Message-ID: <3a0fe06c@news1.idx.com.au>
X-Deja-AN: 693041238
References: <8tgikk$gk6$1@bugstomper.ihug.com.au>
X-Original-NNTP-Posting-Host: tntwc01-3-03.idx.com.au
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Complaints-To: abuse@telstra.net
X-Trace: nsw.nnrp.telstra.net 974118406 203.14.30.196 (Mon, 13 Nov 2000 23:26:46 EST)
Organization: Customer of Telstra Big Pond Direct
X-MSMail-Priority: Normal
NNTP-Posting-Date: Mon, 13 Nov 2000 23:26:46 EST
Newsgroups: comp.lang.java.help,comp.lang.java.programmer,aus.computers.java