Padd Solutions

Converted by Falcon Hive

import java.util.Scanner;

public class Factorial
{
    public static void main (String[] args)
    {
        //non-negative integer
        Scanner scan = new Scanner (System.in);
       
        int a, total=1;
       
        System.out.print ("Enter a nonnegative number. ");
        a = scan.nextInt ();
     
        while (a >= 2)
        {
            total *= a;
            a--;
        } 
       
       
        System.out.println ("The factorial is "+total);
    }
}
           

(0) Comments

Post a Comment