Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Factorial{
- public static void main(String args[]){
- int yourNumber = 0;
- Scanner Geoff = new Scanner(System.in);
- System.out.println("Give me a number: ");
- yourNumber = Geoff.nextInt();
- System.out.printf("The factorial of your number is %d", factorial(yourNumber));
- }
- public static int factorial(int n){
- if (n == 1){
- return n;
- }
- else{
- return n * factorial(n-1);
- }
- }
- }
Add Comment
Please, Sign In to add comment