Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Finding a Factorial using while loop 
 

In this example we are going to find out the factorial of 12 by using the while loop. In while loop the loop will run until the condition we have given gets true. We are using the scriptlet to calculate the factorial of 12.

 

Finding a Factorial using while loop

                        

In this example we are going to find out the factorial of 12 by using the while loop. In while loop the loop will run until the condition we have given gets true. We are using the scriptlet to calculate the factorial of 12. In the scriptlet we generally writes a java logic in it. The output will be displayed by using the out implicit object used to write the content on the browser.

We can find a factorial of a number by using the temp variable which will help us to calculate the factorial of a number. Take one variable factorial of int type and initialize it as 1. Take another variable value of type int of which you want to calculate the factorial .Now use while loop and pass the condition that until temp> 0, the loop should perform the following task: the factorial =  factorial* temp and keep on decreasing the value of temp by l.

Code of the Program:

<HTML>
  <HEAD>
    <TITLE>Finding a Factorial using while loop</TITLE>
  </HEAD>
  <BODY>
    <font  size="6" color ="#000080">
     Finding a Factorial using while loop</font><br>
    <%
        int value = 12, factorial = 1, temp = value;
        while (temp > 0) {
            factorial *= temp;
            temp--;
        }
     out.println("The factorial of " + value + " is " + factorial + ".");
    %>
  </BODY>
</HTML>

The output of the program is given below:

Download WhileFactorial.jsp.


                        

» View all related tutorials
Related Tags: c math ide data div vi value number ddl id set element elements average mount to e ics in cs

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.