Factorial using while loop
import java. util. Scanner;
class Fact {
public static void main (String [ ] arg) {
Scanner obj = new Scanner (System.in ) ;
int f=1;
System.out.println (" Enter the no :- ") ;
int a = obj. nextInt() ;
while (a>=1) {
f=f*a ;
a-- ;
}
System.out.println (" Factorial " + f) ;
}
}
0 comments:
Post a Comment