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.
Java basics, conditional, switch, loops, arrays, methods and inheritance articles and programs.
Search This Blog
UI/UX Design | Web Development | Mobile Application Development
Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us
Subscribe to:
Post Comments (Atom)
I wish to commence with $2 via alertpay. Help me.
ReplyDeleteHere is my website www.hyipmanagerscript.com
What type of help do you need?
DeleteIts such as you read my mind! You appear to understand so much about this,
ReplyDeletesuch 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
pls show me the output of this program
ReplyDeleteSuppose a=5
ReplyDeleteb*=a
Represents b=b*a
We already have b=1
So b=1*5
later it checks the condition (a>0)
so condition is true
So then
a--
it represents 4
now the ouput of b=5 will be mutiplued with 4 it will become 20 now b=20
Then it checks condition (a=4<0) true aagain a-- it will become 3 again it is munyiplied with 2 and then 1