Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FactorialNumber {
- public static void main(String[] args){
- Scanner inputObject = new Scanner (System.in);
- System.out.print("Type a number [0-20]: ");
- int factorialNumber = Integer.parseInt(inputObject.nextLine());
- if (factorialNumber != 0){
- long factorialRes = 1, factorialCount = 2;
- while (factorialCount <= factorialNumber) {
- factorialRes *= factorialCount;factorialCount++;
- } System.out.println("Factorial: " + factorialRes);
- } else {
- System.out.println("Factorial: 1");
- }
- inputObject.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement