Menu

不使用第三个变量交换两变量的值

/**
    有两个整数 分别是 a=10 b=8 在不使用第三个变量的情况下  对其值进行交换
*/
class Work1{
    public static void main(String[] args){
        int a = 10;
        int b = 8;
        /*
        a=a+b;
        b=a-b;
        a=a-b;

        a=a^b;
        b=a^b;
        a=a^b;
        1010
        1000
        ----------
        0010 2

        0010
        1000
        -----
        1010 10

        0010
        1010
        -----
        1000 8

        */
        a=b+(b=a)*0;
        System.out.println("a="+a+",b="+b);
    }
}
— 于 共写了250个字
— 文内使用到的标签:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax