Sunday, January 23, 2011

Java101: Factorial

import java.io.*;
public class try2{
public static void main(String args[]) throws IOException{

BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number");
int x= Integer.parseInt(object.readLine());

for(int a=x;a>0;a--){
System.out.println("Entering: "+a);
}
int factorial=1;
for(int b=1;b<=x;b++){
factorial=factorial*b;
System.out.println("Returning: "+factorial);
}


}
}

0 comments:

Post a Comment