diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index 584613774478ed75799e134a70d7a8a5c0c1f3d0..8a50c45e7ab596f86aa173f7fd16a372db0b9772 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -2280,6 +2280,25 @@ while (counter++ < 10) { </m:math> </informalequation> + <para>In addition the factorial of zero is being defined + as:</para> + + <informalequation> + <m:math display="block"> + <m:mrow> + <m:mrow> + <m:mi>0</m:mi> + + <m:mo>!</m:mo> + </m:mrow> + + <m:mo>=</m:mo> + + <m:mn>1</m:mn> + </m:mrow> + </m:math> + </informalequation> + <para>Write an application asking a user for an integer value and calculate the corresponding factorial e.g.:</para> @@ -2294,11 +2313,11 @@ while (counter++ < 10) { System.out.print("Enter an integer value: "); final int value = scan.nextInt(); - long factorial = value; - int i = value; + long factorial = 1; + int i = 1; - while (1 < --i) { - factorial *= i; + while (i++ < value) { + factorial *= i; } System.out.println(value + "! == " + factorial);