|
#1
|
|||
|
|||
import java.util.Scanner; import java.text.DecimalFormat; public class Eggs { public static void main(String[] args) { int count,formula,lowerLimit,upperLimit,answer=1; Scanner input = new Scanner(System.in); System.out.print("FACTORIAL\n"); System.out.print("Lower Limit ="); lowerLimit=input.nextInt(); System.out.print("Upper Limit ="); upperLimit=input.nextInt(); for(count = lowerLimit; count <=upperLimit; count++) { answer*=count; System.out.println(count +" factorial = " + answer); } } } My incorect output FACTORIAL Lower Limit =5 Upper Limit =8 5 factorial = 5 6 factorial = 30 7 factorial = 210 8 factorial = 1680 Sample run: correct output FACTORIALS Lower Limit = 5 Upper Limit = 10 5 factorial = 120 6 factorial = 720 7 factorial = 5040 8 factorial = 40320 9 factorial = 362880 10 factorial = 3628800 please help |
|
#2
|
||||
|
||||
cauz you don't know what factorial is ... first revise factorial section in your maths book..
factorial 5 = 5! = 5*4*3*2*1 = 120 your formula is wrong... you don't need lower limit in formula for it... the lower limit mentioned above is you need to call ur factorial function with those parameters... here is an example.. i used ur code and deleted redundant info... Other suggestion : code without proper indentation makes life hard.. so enable auto indent of your editor if it is not.. or use notepad++ (windows) or eclipse or emacs (unix/windows) Answer I got it :- factorial = 3628800 |
|
#3
|
||||
|
||||
Do an IRC Search for Java app Programming.
Join Channel and ask what ever you want....Lots of People on Line to help out and shoot the &*^% LOL Also....I am not a Java Programmer, but the code looks like recurrsion? Great if it was Pascal or Modula II or even C. But never heard of Java having support for Recurrsion....I could be VERY Wrong here. Best of Luck DN |
|
#4
|
||||
|
||||
Good catch RDA......
It's Been a While since I have ben out of School.....close to 20 years.....LOL |
|
#5
|
||||
|
||||
I can understand...
for me , luckily I was working on some java project and my eclipse was open.. one sight at the formula and i knew that it was wrong.. so just pasted that code and deleted redundent stuff... took 1-2 mins for every thing.... DN, Good job trying to help other |









