Skip to content

Instantly share code, notes, and snippets.

@joicemjoseph
Created October 19, 2015 09:31
Show Gist options
  • Save joicemjoseph/0fc290321741f9899c82 to your computer and use it in GitHub Desktop.
Save joicemjoseph/0fc290321741f9899c82 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class Factorial
{
int p;
public int n;
Factorial()
{
p = 1;
}
int fact()
{
for(;n>=1;n--)
{
p *= n;
}
return p;
}
}
class Fact
{
public static void main(String[] args)
{
Factorial f = new Factorial();
Scanner s = new Scanner(System.in);
System.out.print("Enter the number : ");
f.n = s.nextInt();
int fc = f.fact();
System.out.println("Factorial = "+fc+"\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment