day03 Java Basics

Source: Internet
Author: User

1. Interview questions

(1) Short s=1;s=s+1;

(2) Short s=1;s+=1;

There is no problem with the above two lines of code, if so, where is the problem?

A: The first problem, s+1 is the value of int type, assigned to short s, compile error;

The second s+=1 is not equivalent to s=s+1; it is equivalent to s= (the data type of s) (S+1), which has a casting process.

2, ^ (XOR) Characteristics: One data to another data bit XOR or two times, the number itself is unchanged

For example: int a=10;int b=20;

a^b^b=10;a^b^a=20;

Based on this feature, an application of ^ is able to do a simple data encryption.

Interview question: Exchange the value of a and B with an XOR operator.

A=a^b;

B=a^b;//b=a^b^b=a;

A=a^b;//a=a^b^a=b;

3, <<: Left to the left highest bit discarded, 0 on the right

>>: The right shift is 0, the left side is 0, the highest is 1, the left side is 1

>>>: Unsigned right shift whether the highest bit is 0 or 1, the left side is 0

Example:24>>2=6;

24>>>2=6;

-24>>2=-6;

-24>>>2=1073741818;

day03 Java Basics

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.