The big question of Java FAQ

Source: Internet
Author: User

Import Java.util.*;import Java.math.biginteger;public class fiftysixth{public        static void Main (string[] args) {                BigInteger one = new BigInteger ("$");                BigInteger The new BigInteger ("the");                BigInteger three = new BigInteger ("50000");                BigInteger total = Biginteger.zero;                Total.add (one);                Total.add (both);                Total.add (three);                SYSTEM.OUT.PRINTLN (total);}        }

How much output?

0

How could it be? Isn't it a plus?

Note that BigInteger is an immutable type.

Immutable types:

String,integer,bigdecimal,long,charactor,short,byte,boolean,float,double

And look at the BigInteger method:

BigIntegeradd(BigInteger val)Returns a BigInteger whose value is(this + val)

BigInteger divide(BigInteger val)Returns a BigInteger whose value is (this / val) .

int intValue()Converts this BigInteger to an int .

BigIntegernegate()Returns a BigInteger whose value is(-this)

BigIntegersubtract(BigInteger val)Returns a BigInteger whose value is (this - val) .

It can be observed that the return value of subtraction is BigInteger, which also means that the final operation is to return the result, but does not change the original value.

I can understand that.

int i=0;

i+1+2+3+4+5+6;

So what is the value of I? Of course it's 0!!!

The big question of Java FAQ

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.