Home Answers Viewqa Java-Beginners Calculate factorial of a number.

 
 


ratna rathor
Calculate factorial of a number.
2 Answer(s)      a year ago
Posted in : Java Beginners

How to calculate factorial of a given number?

View Answers

May 23, 2012 at 6:00 PM


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Factorial {
    public static void main(String args[]) throws IOException {
        System.out.println("Please Input Any Number");
        int num = 0;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String data = (String) br.readLine();
        num = Integer.parseInt(data);
            int result = num;
        for (int i = 1; i < num; i++) {
            result = result*i;
        }
        System.out.println(result);
    } }

Description: - Factorial of any number n is represented by !n and is equal to n(n-1)(n-2)(n-3)?.1. BufferReader () is used for user input.BufferReader consider inputted value as String so for int value you have to use Integer.parseInt(). For loop from 1 to num-1 calculating the factorial value of num as result=result*i. Initial value of result is num.


May 25, 2012 at 12:23 AM


Explanation : Java supports recursion. Recursion is the process of defining something in terms of itself. As it relates to java programming, recursion is the attribute that allows a method to call itself. A method that calls itself is said to be recursive.

The classic example of recursion is the computation of the factorial of a number. The factorial of a number N is the product of all the whole numbers between 1 and N. for example, 3 factorial is 1Ã?2Ã?3, or 6. Here is how a factorial can be computed by use of a recursive method









Related Pages:
Calculate factorial of a number.
Calculate factorial of a number.  How to calculate factorial of a given number?   import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Factorial { public static
Write a program to calculate factorial of any given number
program to calculate factorial of any given number. First of all define a class... Factorial Examples - Java Factorial Example to calculate factorial of any... the factorial of number in double which is lies in the range of double data type
Calculate factorial Using Recursion
to calculate the factorial. The number we have entered in the html page...Calculate factorial Using Recursion  ... through this example you will be understand how you can calculate the factorial
Finding a Factorial using while loop
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... gets true. We are using the scriptlet to calculate the factorial of 12
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
factorial of fibonacci
factorial of fibonacci   A code for the factorial of a fibonacci series. Example when the user enters 6, the fibonacci series is 8 and the factorial will be 8! or 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1. So if the user enters the number 6
Finding a Factorial using while loop
the scriptlet to calculate the factorial of 12. In the scriptlet we generally writes... 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
find factorial of any number using recursion
find factorial of any number using recursion  error in 14 line ; expected int rec( int a) ^ how to resolve this.please correct the code. import...)); System.out.println(?enter number?); int x=Integer.parseInt(br.readLine()); int result
Java Swing Compute Factorial
Java Swing Compute Factorial In this section, we are going to find the factorial of a given number. Here an user is allowed to enter a number into the text...("Factorial of Input Number: "); t1 = new JTextField(20); t2 = new
How to get factorial in mysql
alot for a function in mysql to find factorial numbers of a number and couldn't...How to get factorial in mysql  Hi, In order to improve the speed.... example: for 1155, the factorial numbers would be: 3, 5, 7, 11 Thank you
Write a program to find a factorial in any given number
Write a program to find a factorial in any given number This programming tutorial will teach you how to write a factorial of any given number... the factorial of any given number import java.util.Scanner; class
factorial using recursive
factorial using recursive  can please give this code !i am going to do a factorial function using recursion definition and then . my professor told... OR NO..after that if yes : ENTER NUMBER: id try again input another number. if no back
Calculating factorial in JRuby
in this example you will know to "Calculate Factorial in JRuby". In this example we have defined a function factorial( number) which takes the number... Calculating factorial in JRuby   
How to calculate number of weeks in a specified month
How to calculate number of weeks in a specified month  I am create... select year and month. then automatically calculate number of weeks in a specified... then display number of weeks in cmbweek combo box. ex 1week 2week 3week 4week
calculate average
calculate average   Design and write a java program to determine all... to the original number. abc = a^3 + b^3 + C^3 ( NOTE 407 is one of them) 2.Design and write a program and calculate your final average in this course. The details
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need.... The desired interval can then be determined by dividing that number
Calculate total number of elements remaining in the buffer.
Calculate total number of elements remaining in the buffer. In this tutorial, we will discuss how to calculate total number of elements remaining...     .println("Number of remaining elements 
Printing Table in JRuby
studied how to run program in JRuby and to calculate factorial in JRuby. Now... to calculate factorial and generate result according to given value. Output... print " Enter number to print table := " n= gets  1.upto(10) do |i
Factorial Program in Java
the number 5 Factorial of 5: 120.0...Factorial program in Java helps programmer to write factors of any given integer number. In the following example, a class by the name "Factorial1" is used
Calculate sum and Average in java
Calculate sum and Average in java  How to calculate sum and average in java program?   Example:- import java.io.BufferedReader; import... the sum by the total number of numbers, we have determined the average of numbers
find the factorial
find the factorial  how to find the factorial through the while loop...) { int value = 5, factorial = 1, temp = value; while (temp > 0) { factorial *= temp; temp
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format using javascript. can anyone suggest me how to work it outin calculating
Week calculate start from friday
Week calculate start from friday  My problem is to calculate how many weeks have a month. Note that my weeks have to start on Friday! I have three... number of weeks for the selected month. example: if i select year in 2010 month
how to calculate max and min - RUP
how to calculate max and min  hye!i'm a new for the java and i want to ask a question . Could anyone help me to teach how to calculate the maximum... void main(String args[]) { // Method for the max number among the pair
Modify the sales tax program to accept an arbitrary number of prices, total them, calculate the sales tax and print the total amount.
Modify the sales tax program to accept an arbitrary number of prices, total them, calculate the sales tax and print the total amount.  Modify the sales tax program to accept an arbitrary number of prices, total them, calculate
factorial - Java Beginners
factorial Example in Java  The factorial method is used frequently in probability problems. The factorial of a positive integer n (written as n!) is equal... class Factorial Example{ public static long factorial(int n){ if(n <
Calculate the Sum of three Numbers
how to calculate three integer number . First of all define class name "... Calculate the Sum of Three Numbers   ... . In this section you will learn how to calculate the sum of three numbers by using three
How to calculate area of triangle
.style1 { margin-right: 0px; } How to Calculate...; In this section we will learn how to calculate area of triangle. We... are going to define three character type values for static variable. To calculate
how to calculate max and min in the loop - Java Beginners
how to calculate max and min in the loop  thanks coz giving me... static void main(String[] args) throws IOException { // Max Number to be inputted System.out.println("Enter Number to be input: "); BufferedReader
Find in Array - Calculate Occurrences of Elements in Array
Find in Array - Calculate Occurrences of Elements in Array... to calculate occurrences of elements in an array. Occurrences means, the how many...(ne.getMessage() + " is not a number!"
Having a hard time writing program to calculate test scores..........
Having a hard time writing program to calculate test scores.......... ... to have your program open the data file, count the number of elements in the file... into the array. Then calculate and output the following statistics: average score
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum... numbers from the file and then calculate their sum. Here is the code
how can you calculate you your age in daies??
how can you calculate you your age in daies??  **hi, I am beginner in java! can any one help me to write programm to calculate age in daies...(); System.out.print("Enter month(in number) of your date of birth: "); int month
C calculate sum of first and last element of array
C calculate sum of first and last element of array In this section, you will learn how to calculate sum of first and last element from the array of five... enters the number. Then using the index of the array, we have found first
Addition of two Number in Class
;    In this program we will learn how to calculate the sum of any two number. Java is a object oriented  programming language...; we are going to use addition of  two number. First of all, we have
Example - Factorial
Java NotesExample - Factorial Factorial n (usually written n... a recursive factorial function is a mistake because The recursive solution's memory... numbers that factorial generates cannot be represented in the limited range
calculate average
calculate average  Question 2 cont.d Test case c: home works/labs 10 9 9 9 10 10 9 9 10 10 9 9 10 test scores: 65 89 note, the program should work with different numbers of home works/labs
Magic number Java Program
then calculate the number the person is thinking of by simply adding up the first number...Magic number Java Program  write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between
calculate the time ..
calculate the time ..  [CODE] Elapsed Time Example <script type="text/javascript"> var startTime = null...="button" value="Calculate Difference" onclick="calculateTimeElapsed();" />
Convert Number to Binary
Convert Number to Binary       In this section, you will learn to convert a number to a binary (0,1). The given number is a decimal format and the following program to calculate its
Find out the prime number
factorial other than 1 and the number itself.   Here, first make a class... Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
calculate reward points.
calculate reward points.  How to calculate reward points in a multiplex automation system
Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque.
Write a program that makes use of a class called Employee that will calculate... of a class called Employee that will calculate an employee's weekly paycheque. Design...: A static field, empCount, keeps track of the number of instantiated employees
How to calculate attending hours?
How to calculate attending hours?  I need to calculate attending hours of a employee in a day in my project to make their monthly salary . By using work starting time and ending time. How should I do it using Date class? Or any
Sum of a Number using Swing
Sum of a Number using Swing       In this section, you will learn how to sum of a number using swing...; JButton button = new JButton("Calculate"
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.