The Jave Source Code Program I will be sharing to you is a very memorable to me. Memorable because this was the problem given on our Prelim Exam which gave me a perfect score.
A Java Source Code of Factorial Program. This java program asks you to Enter a valid integer number and then prints the factorial number of that inputted integer as the result.
For example, if you enter an integer number "3". The java program will calculate the factorial of that number (3*3*3) which is equal to "27". The program will print the factorial number at the next line.
Here's the source code:
Source: http://chortle.ccsu.edu
A Java Source Code of Factorial Program. This java program asks you to Enter a valid integer number and then prints the factorial number of that inputted integer as the result.
For example, if you enter an integer number "3". The java program will calculate the factorial of that number (3*3*3) which is equal to "27". The program will print the factorial number at the next line.
Here's the source code:
import java.io.*;
// User enters integer N. The program calculates N factorial.
//
class factorial
{
public static void main (String[] args ) throws IOException
{
BufferedReader userin = new BufferedReader
(new InputStreamReader(System.in));
String inputData;
long N, fact = 1;
System.out.println( "Enter Number:" );
inputData = userin.readLine();
N = Integer.parseInt( inputData );
if ( N >= 0 )
{
while ( N > 1 )
{
fact = fact * N;
N = N - 1;
}
System.out.println( "The Factorial is: " + fact );
}
else
{
System.out.println("N must be zero or greater");
}
}
}
Source: http://chortle.ccsu.edu



0 comments:
Post a Comment