Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class FactorialNumber {
  3. public static void main(String[] args){
  4.  
  5. Scanner inputObject = new Scanner (System.in);
  6. System.out.print("Type a number [0-20]: ");
  7. int factorialNumber = Integer.parseInt(inputObject.nextLine());
  8.  
  9. if (factorialNumber != 0){
  10. long factorialRes = 1, factorialCount = 2;
  11. while (factorialCount <= factorialNumber) {
  12. factorialRes *= factorialCount;factorialCount++;
  13. } System.out.println("Factorial: " + factorialRes);
  14. } else {
  15. System.out.println("Factorial: 1");
  16. }
  17. inputObject.close();
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement