public static double jackpotChance(int k, int highestNumber, int m)
{
long temp = 1;
long tempK = 1;
for(int i = 0; i < k; i++)
{
temp = temp * (highestNumber-i);
System.out.println(temp);
}
for(int u = 0; u < k; u++)
{
tempK = tempK * (k-u);
System.out.println(tempK);
}
double jackpotChance;
jackpotChance = (temp/tempK)*m;
return jackpotChance;
}
Going above ~30 for highestNumber will give a false number for temp thus giving me a false number for jackpotChance. I have heard of BigNumber in the java.math class, and I tried to use that, but it wouldn't let me convert to between number types for some reason. Any advice would be much appreciated. Yes this is a homework problem, so if you can give advice without giving the answer that'd be great thanks :)
edit: added the BigInteger for reference. The error I'm getting is it can't convert the 1 into a BigInteger.
public static BigInteger jackpotChance(int k, int highestNumber, int m)
{
BigInteger temp = 1;
BigInteger tempK = 1;
for(int i = 0; i < k; i++)
{
temp = temp * (highestNumber-i);
System.out.println(temp);
}
for(int u = 0; u < k; u++)
{
tempK = tempK * (k-u);
System.out.println(tempK);
}
BigDecimal jackpotChance;
jackpotChance = (temp/tempK)*m;
return jackpotChance;
}