>java -d destinationfolder Classname.java
javac classname.java
To run use command as :
java classname.
The following is an example to find the factorial of a number.
[java]
class FactorialExample{
public static void main(String args[]){
int i,fact=1;
int number=5;//It is the number to calculate factorial
for(i=1;i<=number;i++){
fact=fact*i;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}
[/java]
The factorial is normally used in permutations and combinations, in the above example, for loop is used to compute the result, the same can be done with recursion also.
Output:
The following is the result will be displayed.
[java]
Factorial of 6 is: 720
[/java]
System.out.println("");
is used to print the statements.