首页 > 代码库 > public static void Swap2
public static void Swap2
public class Swap2 { public static void Swap2 (IDemo a, IDemo b) { int temp = a.i; a.i = b.i; b.i = temp; } public static void main (String args []) { IDemo a, b; a = new IDemo ( 10 ); b = new IDemo ( 20 ); System.out.println ( "a is " + a); System.out.println ( "b is " + b); Swap2.Swap2 (a, b); System.out.println ( "a is " + a); System.out.println ( "b is " + b); } } class IDemo { protected int i; public IDemo(int _i) { i=_i; } public String toString() { return String.valueOf(i); } }
---------- java ---------- a is 10 b is 20 a is 20 b is 10 Output completed (1 sec consumed) - Normal Termination
public static void Swap2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。