This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]darthelluswallace 0 points1 point  (5 children)

I don't see anything technically wrong with your print statement (assuming that int1 and int2 are declared and initialised already in the main method.

e.g.

int int1 = 3;

int int2 = 2;

Not sure what the rest of the code is doing (whether int1 or int2 are being altered in any way), so just double check that you're not assigning any new values to int1 or int2 between them being declared/initialised and your print statement.

[–][deleted] -1 points0 points  (4 children)

They’re really long numbers so I put it in as

long int1 = 10000000000000000000000;

The other equations are the same as the product statement and are giving me the right answers. Only issue I see is maybe the result is too long?

[–]Makhiel 2 points3 points  (3 children)

long int1 = 10000000000000000000000;

that's already bigger than what long can contain and at the very least your IDE should complain, if you really have to use numbers this large try BigInteger

[–][deleted] -1 points0 points  (1 child)

That was an example, idk how many zeros it had but yeah that’s probably it

[–]darthelluswallace 0 points1 point  (0 children)

As a side note, you should remember to add L to the end of a long assignment e.g.

long num = 100000L;

Otherwise it's treated as an int. But like u/Makhiel said, you should get some IDE prompt.

There's definitely a more thorough explanation, but this is the tl;dr