看这短些个吧,错误差不多. import corejava.*; import java.math.*; public class BigIntegerTest { public static BigInteger lotteryOdds(int high, int number) { BigInteger r=new BigInteger("1"); int i; for(i=1;i<=number;i++) { r=r.multiply(BigInteger.valueOf(high)).divide(BigInteger.valueOf(i)); high--; } return r; // TODO: Add your code here } public static void main(String[] args) { int numbers=Console.readInt("How many numbers do you need to draw?"); int topNumber=Console.readInt("What is the highest number you can draw?"); BigInteger oddsAre=lotteryOdds(topNumber,numbers); System.out.println("Your odds are I in"+oddsAre+".Good luck!"); // TODO: Add your code here } }
import corejava.*;
import java.math.*;
public class BigIntegerTest
{
public static BigInteger lotteryOdds(int high, int number) {
BigInteger r=new BigInteger("1");
int i;
for(i=1;i<=number;i++)
{
r=r.multiply(BigInteger.valueOf(high)).divide(BigInteger.valueOf(i));
high--;
}
return r;
// TODO: Add your code here
} public static void main(String[] args) {
int numbers=Console.readInt("How many numbers do you need to draw?");
int topNumber=Console.readInt("What is the highest number you can draw?");
BigInteger oddsAre=lotteryOdds(topNumber,numbers);
System.out.println("Your odds are I in"+oddsAre+".Good luck!");
// TODO: Add your code here
}
}