Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Thursday, 7 July 2011

Write a program to print factorial of any number using do while loop

import java.util.*;
class factorial
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);

int a,b=1;
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();

do
{
b*=a;
--a;
}while (a>0);

System.out.println ("\n\t Factorial = "+b);

}
}

Note:
        In this program first of all body of the loop will be executed then its condition will be checked if it is true then body of the loop will be executed again otherwise not. This will continue until a=0. When a=0 the loop will be broken and the next statement to it will be executed.

4 comments:

  1. I wish to commence with $2 via alertpay. Help me.
    Here is my website www.hyipmanagerscript.com

    ReplyDelete
  2. Its such as you read my mind! You appear to understand so much about this,
    such as you wrote the e-book in it or something.
    I think that you just could do with a few % to force the message home a bit, however instead of that, this is great blog. A fantastic read. I'll certainly be back.
    Also visit my blog :: optin emails purchases

    ReplyDelete
  3. pls show me the output of this program

    ReplyDelete