This is my first Java application strange, I wanted to implement an arbitrary accurate factual function, I recurs a fine But one of my walking bus produces "1" and nothing else .. It's too late for me, I do not know why, I'm not sure where I am wrong, is there something clear here ?
Public Fixed BigInteger ifact (BigInteger n) {BigInteger ret = new BigInteger ("1"); BigIntega i = New BigInteger ("1"); (I = New BigInteger ("0"); i.compareTo (n) == 0; i.add (New BigInteger ("1")) {ret.multiply (i); } Return return; }
If you did not notice that it uses the BigInter package, then weighs strange articles ..
In addition, like C, You can do something similar to Type Typeface, do I need to type "BigInteger" every time?
Edit : I think that I can ret
to n
, it may be, or ... maybe not .
Your "TypeF" question, no, you can not do this in Java
For your code, there are several mistakes in it that your loop will be executed only once, and only if ni is equal. You start at 1 in the beginning of the loop and then why do 0? Why do you ignore the results of i.add (...)
? Why do you ignore the result of ret.multiply (i)
? Remember, these methods do not change BI!
It includes those changes:
BigIntegar n = BigInter.valouf (10); BigInteger ret = BigInteger.ONE; (BigIntega i = BigInter.on; i.compareTo (n) & lt; = 0; i = (i.add.bigentier.one); {ret = ret.multiply (i); } System.out.println (ret);
Comments
Post a Comment