Last active
August 29, 2015 14:00
-
-
Save YuukiARIA/11032803 to your computer and use it in GitHub Desktop.
Java swap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ご指摘ありがとうございます。修正致しました。
この度は誠に申し訳ありませんでした。
今後ともよろしくお願い致します。