Factorial of a number

The demo illustrates finding the factorial of a number, accepted from a user on console. We need to create two classes, Number and Test. The class Number contains the method ‘factorial‘ which can be accessed from the static main method by creating the object of the Number class.

I hope everything is pretty much clear. For any queries on this, you can post in your views/comments.

Some important points to note:

  • Scanner class implements Iterator<String> interface.
  • It parses the String and primitive types using regular expressions. By default, it breaks the input using a white space into separate tokens. Later these tokens are converted to the data types accordingly using the various next methods.


  • System class belongs to the java.lang package and cannot be instantiated.

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.