Re: swap method in Java

From: Stefan Ram (ram_at_zedat.fu-berlin.de)
Date: 06/22/04


Date: 22 Jun 2004 21:47:53 GMT

breyn12345@hotmail.com (Bill Reyn) writes:
>/* this swaps 2 integers correctly, BUT its seems non-OO */
>class Swap4
>{
> static int x=5, y=7 ; // this looks horrid!
> public static void main(String [] args){
> WorkItOut w = new WorkItOut();
> w.swaps(x,y);
>System.out.println( " x (was 5)now is " + x + " y (was 7) now is " + y);
> }

  When is it not applicable to swap the variable names in
  the rest of the block? I.e.,

class Swap4a
{ final static int x=5, y=7 ;
  public static void main( final String[] args )
  { System.out.println( "x now is " + y + " y now is " + x ); }}



Relevant Pages

  • Re: How to swap two variable later?
    ... public string Second ... > Class "Swap" is construncted in "Main" with two initial> variables. ... > public class MyClass ... > public static void Main ...
    (microsoft.public.dotnet.languages.csharp)
  • How to use Log4net TelnetAppender and Trace Listeners
    ... Is there a way to use Log4net and Trace Listeners? ... public static void Initialize(string traceListeners, ... public static void Flush2File(string file, string msg, bool ...
    (microsoft.public.dotnet.framework)
  • Re: must find print packages which can deal with large charts
    ... list available printers, query a named printer, print text and image files ... String inputFileName = null; ... printToFile(outputFileName, outputFileType, ... public static void queryServices{ ...
    (comp.lang.java.gui)
  • nullpointer exception while try to retrieve the elements from the array object
    ... Menu mainMenu = new Menu; ... public static void getConsolidateMenu(Menu menu, Element current, ... mainMenu.setSubMenu(subMenu); ... String description; ...
    (comp.lang.java.programmer)
  • Re: alternative to my ClassLoader hack
    ... public static void main(String... ... Just for the record, this runs, but gets an exception. ... String name: /fubar/MyClassLoader.class ... throws ClassNotFoundException, InstantiationException, ...
    (comp.lang.java.programmer)

Loading