+ 3
what's the problem???!
the code below works well for number less than 20 but is goes weird for greater than 20 https://code.sololearn.com/cyWGWca3R3Rd/?ref=app
6 Antworten
+ 4
Because factorial of number larger than 20 does not fit in the size of (int). You have to use a larger datatype for that.
+ 3
what do you mean?how should I use a larger datatype?
+ 3
hamid size of (int) data type is 4bytes which means it can store only value upto 2,147,483,647
To store larger numbers you should go for the datatype with much larger range for example *long* which is double the size of int(long is of 8bytes) , it can store upto 9,223,372,036,854,775,807
But this limit will soon be short because of drastic increase in factorials, so for even larger numbers you should go for arrays
+ 3
thank you so much 👍👍
but Is using arrays give us the largest datatype?there is no larger than that?
+ 3
hamid array is a collection of elements of specific datatype, which gives you freedome to allocate a huge amount of space also.
+ 1
or BigInteger
https://www.geeksforgeeks.org/biginteger-class-in-java/