Write a Java Program that find the factorial of a number


Write a Java Program that find the factorial of a number 
    Week – 1
c)Aim: To Write a Java Program that find the factorial of a number

Source code:
import java.io.*;
import java.util.Scanner;
class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;
System.out.println(“Enter an integer to calculate it’s factorial:”);
Scanner in = newScanner(System.in);
n = in.nextInt();
if ( n < 0 )
System.out.println(“Number should be non-negative.”);
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;
System.out.println(“Factorial of “+n+” is = “+fact);
}
}
}
Expected Output:
Enter an integer to calculate it’s factorial : 6
Factorial of 6 is = 720

Write a Java Program that find the factorial of a number

Have any Question or Comment?

7 comments on “Write a Java Program that find the factorial of a number

[…] Write a Java Program that find the factorial of a number […]

[…] of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all real and imaginary solutions to the quadratic […]

[…] of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all real and imaginary solutions to the quadratic […]

[…] of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all real and imaginary solutions to the quadratic […]

[…] Write a Java Program that find the factorial of a number […]

[…] Write a Java Program that find the factorial of a number […]

[…] of two matrices write a java program that print the fibonacci series for a give number. Write a Java Program that find the factorial of a number Write a Java program that prints all real and imaginary solutions to the quadratic […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.