Home Discussion Discuss: Write a program to calculate factorial of any given number

• ### Thank you!!Israel Wondimu April 16, 2011 at 5:52 PM

Continue.....

• ### javatasreef khan April 19, 2011 at 3:41 PM

what is BufferedReader and parseIntin in the program and what use these in the program.

• ### Factorialshahin April 21, 2011 at 3:53 PM

I want to calculate factorial 256!. How can I do it & how can I display the result.

• ### java basic programsBHARANI KUMAR May 26, 2011 at 1:02 PM

please forward me java basic programs which are mstly asked in interviews

is good

• ### factorialcharito July 4, 2011 at 7:43 PM

how to factor at my age of 17..

• ### LOGIC AND PROGRAMMINGLAGOS,JACKIELOU C. July 29, 2011 at 8:52 AM

THE CODE HELP Me!!!

thank you!!!

• ### forloopjhon August 22, 2011 at 11:08 AM

i need help for calculating the factorial and triangular of a given number.

• ### worked like a charmAshish August 22, 2011 at 12:26 PM

thanks, it worked like a charm, very helpful. :)

• ### javajim rae September 29, 2011 at 5:49 AM

E Factorial Divisibility selected by Joe Horton The number (n!) is de ned to be the product of the n smallest positive integers. Thus 4! = 1 × 2 × 3 × 4. We want to know how many times you can divide 2 into (n!). Since 2 divides 12 once, and 2 divides 4 twice, but does not divide 3 at all, the number of times 2 divides (4!) is exactly three. Write a program to determine the number of times n! is divisible by 2. Input A sequence of positive integers all on one line, separated by spaces, and followed by 0. Output For each input integer n, excluding the last zero, print out a line: ”n factorial is divisible by exactly k 2’s.” Sample input 5 7 2 0 Output should be: 5 factorial is divisible by exactly 3 twos. 7 factorial is divisible by exactly 4 twos. 2 factorial is divisible by exactly 1 twos. (Ignor the bad grammar in the special case when the number of twos is 1.)

• ### hiisriram October 22, 2011 at 11:35 AM

public static String inString(String prompt) { inputFlush(); printPrompt(prompt); return inString(); } public static String inString() { int aChar; String s = ""; boolean finished = false; while (!finished) { try { aChar = System.in.read(); if (aChar < 0 || (char) aChar == '\n') finished = true; else if ((char) aChar != '\r') s = s + (char) aChar; // Enter into string } catch (java.io.IOException e) { System.out.println("Input error"); finished = true; } } return s; } public static int inInt(String prompt) { while (true) { inputFlush(); printPrompt(prompt); try { return Integer.valueOf(inString().trim()).intValue(); } catch (NumberFormatException e) { System.out.println("Invalid input. Not an integer"); } } } public static char inChar(String prompt) { int aChar = 0; inputFlush(); printPrompt(prompt); try { aChar = System.in.read(); } catch (java.io.IOException e) { System.out.println("Input error"); } inputFlush(); return (char) aChar; } public static double inDouble(String prompt) { while (true) { inputFlush(); printPrompt(prompt); try { return Double.valueOf(inString().trim()).doubleValue(); } catch (NumberFormatException e) { System.out .println("Invalid input. Not a floating point number"); } } } }

• ### regarding javaomkar October 27, 2011 at 1:23 PM

nothing u are good enough to handle expectional handling

• ### java technologyyathartha sharma November 28, 2011 at 8:59 PM

this is such a nice site and thanks for the answer

• ### send me same basics of java anuja December 24, 2011 at 9:37 PM

it was gud to refer

very hard :P

• ### how to find sum of series of factorial valuesdevi January 10, 2012 at 7:44 PM

write a program to calculate & print the result of following series 1!+2!+3!+ . . . . . .+n! here n is any given number.

• ### java sabir January 15, 2013 at 12:10 PM

what is recursion and input factorial in java programing

• ### Formula is off by 1Hassan Irgui January 26, 2012 at 11:28 PM

I am just a beginner in Java programming. I looked up your int code for the factorial and compared it to an excel sheet output. I looks like your coding is missing the fact that the system will always start at zero even if your loop says i=1. With you code, the factorial of 5 for example is 24 whereas the real factorial of 5 is 120! Here is my fix for this bug. for (int i= 1; i<=a+1; i++){ fact=fact*i; adding the 1 to a (a+1) corrects the loop and gives an accurate output. Have a great day. Hassan/Canada

• ### java scriptOrlan Villarino March 23, 2012 at 11:28 AM

How to run a program that include on how to block a number

• ### Keywords Ria March 23, 2012 at 9:15 PM

What do the keywords "try" and "catch" mean in the code?

• ### I need one more clarrificationAnudeep July 24, 2012 at 5:14 PM

Thks for posting.. useful example for begineers . i have one doubt why u given "Array out of bounds exception" if the input is double value?? does we can do with double Value??

• ### commentLavas August 21, 2012 at 4:14 PM

Hi, im a begginner, so how do i run it?

• ### javamaruti September 12, 2012 at 11:06 AM

java is best subject

• ### this is correct oneselva September 16, 2012 at 2:16 PM

this is correct: fact=fact*a;

• ### java swingranjeet kumar October 11, 2012 at 2:19 AM

sir, how to display 12 month calendar structure format in frame when i enter year,i only want its interface code plzs suggest me

• ### the dificulty of javaconfuzed November 15, 2012 at 1:17 AM

this program gave me cancer

• ### computer sincetahrir kilafah May 2, 2013 at 12:48 PM

how i can make database

• ### programNithin joseph August 16, 2013 at 8:24 PM

factorial system definde program

• ### QuestionsNithin joseph August 16, 2013 at 8:28 PM

factoriyal program all?

Subject (*):

Related Articles
Java Tips and Examples

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 given number

Java Beginners

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...("Please Input Any Number"); int num = 0; BufferedReader br = new

Java Tips and Examples

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

Java Beginners

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

Java Beginners

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

JSP Tutorials

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

Java-Tutorials

Factorial Program in Java
Factorial program in Java helps programmer to write factors of any given... exception". Example of Factorial program in Java: import java.io.*; class... the number 5 Factorial of 5: 120.0

JSP Tutorials

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

JSP Tutorials

Finding a Factorial using while loop
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... the scriptlet to calculate the factorial of 12. In the scriptlet we generally writes

Java Beginners

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

Programming Tutorials

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

Java Beginners

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... { System.out.println("Input any No."); BufferedReader br = new BufferedReader(new

SQL Question

How to get factorial in mysql
alot for a function in mysql to find factorial numbers of a number and couldn't find any. What I want to achieve is to find the prime numbers composing an integer...How to get factorial in mysql  Hi, In order to improve the speed

Java-Tutorials

Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other than 1 or itself. Similar logic is used in program will displaying the result

JRuby

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

Java Beginners

program for factorial
program for factorial  how to set size of buttons on frame

Java Beginners

program for factorial
program for factorial  how to set size of buttons on frame

JRuby

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

Java Beginners

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

Java Beginners

How to calculate number of weeks in a specified month
How to calculate number of weeks in a specified month  I am create one program that contain three combo box. 1.cmbyear 2.cmbmonth 3.cmbweek i am select year and month. then automatically calculate number of weeks in a specified

Java Beginners

Write a program that converts any given year to Roman Numeral in Java
Write a program that converts any given year to Roman Numeral in Java  Write a program that converts any given year to Roman Numeral

Java Beginners

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

Java Beginners

Java converts any given year to Roman Numeral
Java converts any given year to Roman Numeral  Write a program that converts any given year to Roman Numeral

Java Beginners

Program to Find Cube Root of any Number without using built in function
Program to Find Cube Root of any Number without using built in function  Please help me in finding cube root of any number without using Built in function in java

Java-Tutorials

Calculate process time in Java
. In this section, an example with the complete code of the program is given... Calculate process time in Java       This section provides the facility to calculate

Java Tips and Examples

Convert Number to Binary
). The given number is a decimal format and the following program to calculate its binary. Code Description: This program takes a decimal number at the console...: Output of this program given below. C:\corejava>java

General

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... variables and type of methods. We are going to use in this program of class

Java Beginners

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

Java Tips and Examples

Find out the prime number
to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know... factorial other than 1 and the number itself.   Here, first make a class

Java Beginners

calculate a list of products
calculate a list of products  Hi can you help me with this java program. This program should allow the user to order from a small catalogue of three items displayed on the screen, then calculate the user's final bill, including

Tutorial Topics
Questions by Category