Skip to content

Instantly share code, notes, and snippets.

@YuukiARIA
Last active August 29, 2015 14:00
Show Gist options
  • Save YuukiARIA/11032803 to your computer and use it in GitHub Desktop.
Save YuukiARIA/11032803 to your computer and use it in GitHub Desktop.
Java swap
public class Main
{
private static void swap(Integer a, Integer b) // Integer使って参照(共有)渡し
{
Integer t = a;
a = b;
b = t;
}
public static void main(String[] args)
{
Integer a = 1, b = 2;
System.out.printf("%d,%d\n", a, b); // ==> 1,2
swap(a, b);
System.out.printf("%d,%d\n", a, b); // ==> 1,2
}
}
@YuukiARIA
Copy link
Author

ご指摘ありがとうございます。修正致しました。
この度は誠に申し訳ありませんでした。
今後ともよろしくお願い致します。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment