fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Zahl a = new Zahl(2);
  13. Zahl b = new Zahl(3);
  14.  
  15. System.out.println("a vorher: " + a.wert);
  16. System.out.println("b vorher: " + b.wert);
  17.  
  18. swap(a, b);
  19.  
  20. System.out.println("a nachher: " + a.wert);
  21. System.out.println("b nachher: " + b.wert);
  22. }
  23.  
  24. public static void swap(Zahl a, Zahl b) {
  25. int temp = a.wert;
  26. a.wert = b.wert;
  27. b.wert = temp;
  28. }
  29. }
  30.  
  31. class Zahl {
  32. public int wert;
  33.  
  34. public Zahl(int wert){
  35. this.wert = wert;
  36. }
  37. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
a vorher: 2
b vorher: 3
a nachher: 3
b nachher: 2