int and Long in Java

Source: Internet
Author: User

Today in the time stamp of the conversion program to find out how to write the wrong, only to find the original

Long A1 = 10;

This code does not directly transform 10 into a long, allocated memory or int length

Need to write long a1 = 10L;

The errors that are very easy to make when writing code are:

Long a3 = 1422206881*1000;

This time 1422206881*1000 obviously has overflowed int length (32 bit), but the compiler does not prompt the error, in memory A3 is an int, only 32 bits are stored.

Then the value of the next A3 is obviously wrong.

SYSTEM.OUT.PRINTLN (A3); The result is shown as: 572706024

The correct notation is to initialize a long type of variable write must be after the number plus L!

int and Long in Java

Related Article

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.