欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java实现swap方法,java实现swap,以前笔试时候的一个题,现

来源: javaer 分享于  点击 9210 次 点评:16

java实现swap方法,java实现swap,以前笔试时候的一个题,现


以前笔试时候的一个题,现在拿来练练手

[Java]代码

public class TestSwap {    /**     * @param args     */    //定义类变量    static int a = 3;    static int b = 2;    public static void main(String[] args) {        TestSwap ts = new TestSwap();        System.out.println("before swap  "+"a的值="+a+" b的值="+b);        ts.swap(ts.a,ts.b);        System.out.println("after  swap  "+"a的值="+a+" b的值="+b);    }//改变的是类变量的值    private static void swap(int m, int n) {        int temp;        temp = a;        a = b;        b = temp;    }}

未命名.jpg

imgs/asCode/08171711_Tz5Z.jpg
相关栏目:

用户点评