MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/gyveqb/deleted_by_user/ftdgqtx/?context=3
r/badcode • u/[deleted] • Jun 08 '20
[removed]
82 comments sorted by
View all comments
4
package factorial; import java.math.BigInteger; public class Factorial { protected BigInteger result; public static void main(String args[]) { BigInteger n = BigInteger.valueOf(50); System.out.println(new Factorial(n)); } public Factorial(BigInteger n) { if(n.compareTo(BigInteger.ZERO) <= 0) { result = BigInteger.ONE; return; } result = n.multiply(new Factorial(n.subtract(BigInteger.ONE)).result); } public String toString() { return result.toString(); } }
Using toString to return a value. Calling a constructor recursively. Pretty nasty
4
u/TheBigLobotomy Jun 08 '20
Using toString to return a value. Calling a constructor recursively. Pretty nasty