Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class fact{
- public static void main(String a[]){
- Scanner sc = new Scanner(System.in);
- boolean cont = true;
- while(cont){
- System.out.print("Enter the Number : ");
- int number = sc.nextInt();
- long answer = factorial(number);
- System.out.println("The factorial of " + number + " is " + answer);
- System.out.print("\nDo you want to continue (1/0) : ");
- int n = sc.nextInt();
- if(n==0){
- cont = false;
- }
- }
- }
- static long factorial(long number){
- long fact = 1;
- while(number > 0){
- fact = fact*number;
- number = number - 1;
- }
- return fact;
- }
- }
Add Comment
Please, Sign In to add comment