0

I'm sorry to bother you busy people with this probably obvious question, but the compiler wont give me anything except:

Arithmetic.java:4: error: null: 146367789778966
        int myNumber = 3 + 146367789778966;
        ^                 
           1 error

Code

public class Arithmetic {
public static void main(String[] args) {

    int myNumber = 3 + 146367789778966;
    System.out.println(myNumber);

    }
}

If anyone can tell me whats wrong, that would be great!

0

3 Answers 3

4

146367789778966 is too large to fit in an int type.

The max value an int can hold is 2,147,483,647 so the value can't fit inside the int and your code throws the error.

You could use a larger data type like long.

More information on data types: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Sign up to request clarification or add additional context in comments.

3 Comments

I just don't know why it would error as null... probably just something wrong with the installation.
Me either - I get "error: integer number too large: 999999999999"
Oh well, ill call my IDE's support or something, thank you though.
2

The max value for an int is 2,147,483,647. So your number is just too darn big.

Comments

1
  • Integer.MAX_VALUE is actually 2147483647

  • 146367789778966 is bigger than Integer.MAX_VALUE so it cannot be stored in int type

An IDE like IntelliJ will warn you about this :

Error:(10, 28) java: integer number too large: 146367789778966 // what IntelliJ gives me

You can use for ex BigInteger :

BigInteger b = new BigInteger("146367789778966");
b = b.add(BigInteger.valueOf(3));
System.out.println(b)       // 146367789778969

1 Comment

but it doesn't. Read the error, it throws null. Thats My problem now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.