To exchange two variables without using third variable

2010-09-11  来源:本站原创  分类:Java  人气:110 

1, with bit computing:
A = A ^ B
B = A ^ B
A = A ^ B

Second, using addition and subtraction:
A = A + B A = A-B
B = A-B or B = A + B
A = A-B A = A + B

Third, a more simple method:

A = B + ((A = B) & 0)

Hei hei!

相关文章
  • To exchange two variables without using third variable 2010-09-11

    1, with bit computing: A = A ^ B B = A ^ B A = A ^ B Second, using addition and subtraction: A = A + B A = A-B B = A-B or B = A + B A = A-B A = A + B Third, a more simple method: A = B + ((A = B) & 0) Hei hei!

  • The value of the exchange two variables without using third variable 2010-10-05

    int a = 3; int b = 5; Method One: a = a + b; b = a - b; a = (a - b) / 2; b = a + b; Method Two: b ^ = a ^ = b ^ = a;

  • PHP variables and scope & static variable declaration 2010-06-14

    PHP is a weakly typed language, (weakly typed languages that do not specify the use of variable, the variable type, in use, there was no type checking of a class of programming language), so the use of variables, without the prior specified variable

  • How not to use intermediate variables to exchange two variables? 2010-07-10

    int, then on the + and then cut. If the connection string and then intercept. int a, b; a = a + b; / / At this point a to a and b of and b = ab; / / now b = a a = ab; / / then a = b

  • Several commonly used (PHP predefined variable), and (how to access pre-defined variables) 2010-06-01

    REQUEST_METHOD: access the page when the request method. For example: "GET", "HEAD", "POST", "PUT". REQUEST_TIME: request start timestamp. QUERY_STRING: query (query) string (URL of the first question mark? After th

  • java based - identifiers, constants, variables, variable categories 2010-10-04

    Identifiers: 1. Java in a variety of variables, methods and class names and other elements of the sequence of characters used as identifiers Any place they can call a name identifier, are to comply with the rules of identifier 2. Java identifier nami

  • (Transfer) Ubuntu environment variables 2010-02-13

    Environment variable configuration file In Ubuntu, there are several files you can set the environment variable 1, / etc / profile: In the log, the operating system to use when customizing the user environment, the first file, the file system setting

  • linux configure the java environment variables 2010-03-01

    linux configure the java environment variables http://edu.codepub.com/2009/0630/7473.php 1. Download jdk5.0 for linux now use linux more and more a friend few days ago, two friends have asked me how to configure java under linux environment, I think

  • Environment variable settings under LINUX 2010-04-28

    System: SUSE Has on the environment variable is fear, especially on the environment variables take effect immediately or not, and the user environment variable after the switch to maintain or not it is ignorance. Are listed in a reference to the foll

  • Linux operating system environment variables approach three configurations 2010-05-24

    -------------------------------------------------- -------------------------------------------------- -------------- Transfer from: http://www.linuxeden.com/html/sysadmin/20080424/56879.html -------------------------------------------------- --------

  • JAVA face questions FAQ Series (3) - variable (property) coverage [Reserved] 2010-05-27

    We look at such a question: Java code class ParentClass ( public int i = 10; ) public class SubClass extends ParentClass ( public int i = 30; public static void main (String [] args) ( ParentClass parentClass = new SubClass (); SubClass subClass = ne

  • linux java environment variable settings 2010-06-12

    In / etc / profile file to change permissions. And then in a terminal enter sudo gedit / etc / profile. Or use the root user to directly edit. At the end of the file add the following few: export JAVA_HOME = / usr/java/jdk1.5 export PATH = $ JAVA_HOM

  • linux configure the java environment variables (more) 2010-06-18

    Now use linux more and more friends, and there a few days ago two friends asked me how to configure java under linux environment, I think there are a lot of friends want to know this stuff to learn, to write a full point in linux java environment con

  • java environment variable settings 2010-07-01

    Configure JDK under windows xp environment variables: 1. Install JDK, the installation process to customize the installation directory and other information (for example, select the installation directory is D: \ java \ jdk1.6.0_03), I am here to cho

  • linux shell variable environment variable command not found a solution 2010-07-14

    linux shell variable environment variable command not found a solution In Ubuntu, there are several files you can set the environment variable 1, / etc / profile: In the log, the operating system to use when customizing the user environment, the firs

  • How to set Unix environment variables 2010-07-14

    Set Unix environment variables: ----------------------------------- Set the environment variable syntax depends on your use of the shell. First you should determine your login shell, such as: Bourne (sh), Korn (ksh), C shell (csh), perhaps other shel

  • environment variable settings ubuntu 2010-07-14

    Transfer from Small soubo customer http://blog.csdn.net/xiaosu_521/archive/2008/03/09/2160458.aspx Environment variable configuration file In Ubuntu, there are several files you can set the environment variable 1, / etc / profile: In the log, the ope

  • java environment variables 2010-07-21

    1] in My Computer, right click and select [Properties] 2, select the System Properties] [top panel] [Advanced Options, then select the following environment variables] [ 3, in the bottom of the] [System Variables list, find the variable named "JAVA_H

  • C-global variables and local variables 2010-07-21

    http://hi.baidu.com/% C3% E2% B7% D1% B4% F3% BB% B0% D0% F2% C1% D0% BA% C5/blog/item/2d559ddc8f07e2a8cd11661d.html Variables can be three places in the program description: function within the parameters of the function or all of the functions defi

  • C Language Learning variable memory 2010-07-21

    http://zhidao.baidu.com/question/42163882.html?fr=ala0 C language description of the variables include two aspects: the variable type and variable storage type. Variable type, such as: int (plastic), char (character) is used to describe the memory sp