Exchange Values and notes with only two variables

Source: Internet
Author: User

Method 1:

1 int A = 3; 2 int B = 5; 3 A = a + B; 4 B = A-B; 5 A = A-B;

Disadvantage: If a and B are large numbers, they may overflow easily.

Method 2:

Int A = 3; int B = 5; A = a ^ B; B = a ^ B; A = a ^ B;

"^" Is an exclusive or operation, so there will be no overflow problem.

00000011 ^ 00000101 equals 00000110

00000110 ^ 00000101 equals 00000011

 

1. String string + = "ASD ";
The Java compiler will create a new stringbuffer object, convert string into stringbuffer, and then call the append () method and add "ASD ". Convert tostring to the string type.
2. This is the object for obtaining the current call method.
3. Random random = new random (peed); peed is a seed. Different seed produces different random numbers. The same seed produces the same random number when the same number of random times,
Math. Random (); is to call the random method.

Exchange Values and notes with only two variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.