Results 1 to 20 of 26
 11052012, 07:16 PM #1Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
 11052012, 07:35 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: How to make ad factorial table? With and without BigInteger.
Do you know how large 30! is? It's 265252859812191058636308480000000 and it's much larger than Integer.MAX_VALUE; it is even larger than the largest long number.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 11052012, 07:37 PM #3Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
That is true, but do you have any idea on how to actually code the table?
 11052012, 07:41 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
 11052012, 07:50 PM #5Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
I am supposed to make one without BigIntegers, give a reason why it doesnt work, then make one with BigInts and explain why it does.
 11052012, 08:24 PM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: How to make ad factorial table? With and without BigInteger.
Well, you know why using ints (or longs) don't work (30! is larger than that) so build a version that uses BigInts. Tip: n! == n*((n1)!)
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 11062012, 01:56 AM #7Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
The code that you put is giving alot of errors in Netbeans, would something like n= x*(x1) work? any other ideas?
 11062012, 02:01 AM #8Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
This is what I have roght now, and I think it is far off. Right now it is printing one collumn of 030, like it should, but in the other collumn it is just printing 0s all the way down. Any ideas at all on how to fix?
Java Code:public static void main(String[] args) { factorial(); } public static void factorial (){ int x=0, n=5; while (x<30){ x=x+1; while (n>=1){ n= x*(x1); } System.out.println (x+ " "+ n); }
 11062012, 02:02 AM #9
 11062012, 02:05 AM #10
Re: How to make ad factorial table? With and without BigInteger.
Think about what the output would look like. Do you really need 2 loops? Here's how I imagine it:
Java Code:loop { // all printing done on one line print n print space calculate factorial of n print factorial }
 11062012, 02:06 AM #11
 11062012, 02:13 AM #12Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
Srry about that. Ill read that page tonight (on code conventions), as soon as I get this done. Any ideas on what needs to be changed in the formula, to find the factorial of x, after it adds one to x? thanks.
 11062012, 02:19 AM #13
Re: How to make ad factorial table? With and without BigInteger.
Do you understand what factorial is? Try writing out the calculation for facortorial 4 on paper. Then factorial 5, factorial 6. Perhaps you can see a pattern. Then try converting it to code. Do not just grab a code snippet from someone without knowing what it does and expect it to work. Especially since you did not copy it correctly.
 11062012, 02:22 AM #14Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
I do realize what a factorial is and how to solve one on paper, I have been trying on this code for 3 days and cannot figure it out.
 11062012, 02:29 AM #15
Re: How to make ad factorial table? With and without BigInteger.
If you hadn't noticed the pattern here it is:
4! = 1*2*3*4
5! = 1*2*3*4*5
6! = 1*2*3*4*5*6
or
4! = 1*2*3*4
5! = 4! * 5
6! = 5! * 6
This shows that the best way to solve factorial is to use recursion and if you look at the snippet Jos gave you (and the bit you missed) there was another ! at the end of the equation. If you cannot use recursion then you need to calculate it the old fashion way using a loop. BTW why have you initialised n to 5?
 11062012, 02:35 AM #16Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
I didnt miss the !, I got an error when i put it. ')' expected. and ill look into recursion, thanks.
 11062012, 02:38 AM #17Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
And i was trying to test it with some numbers, and dont know how to set them in the actual methods
 11062012, 02:48 AM #18Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Re: How to make ad factorial table? With and without BigInteger.
When I use that code n! == n*((n1)!); tells me the following ';' expected, Not a statement, ';' expected, Not a statement. I think it says ';' expected, because its looking for an operation between n and ! and (n1) and !. How do I fix this?
 11062012, 02:51 AM #19
Re: How to make ad factorial table? With and without BigInteger.
Of course you got an error. The ! means factorial in Math but it is the not operator (as in a != b). Once again this goes back to just grabbing some code snippet without understanding what you are doing.
Java Code:declare a total variable initialise it to 1 declare a factor variable initialise it to 2 while factor is less than target (whatever factorial you are calculating total multiplied by factor increment factor }
 11062012, 03:05 AM #20Member
 Join Date
 Oct 2012
 Posts
 37
 Rep Power
 0
Similar Threads

Factorial method bug
By Mapisto in forum New To JavaReplies: 20Last Post: 12182011, 01:36 AM 
Factorial beginner
By jk91 in forum New To JavaReplies: 4Last Post: 11142011, 11:52 PM 
Factorial in java
By spidey32 in forum New To JavaReplies: 18Last Post: 04092011, 01:04 PM 
factorial sum in java
By java157 in forum New To JavaReplies: 9Last Post: 03172011, 11:07 AM 
Factorial
By Anindo in forum New To JavaReplies: 4Last Post: 07282009, 09:46 PM
Bookmarks