Write a program to find the factorial of a given number using while loop
Answers
Java supports three jump statements: break, continue, and return. These statements transfer control to another part of your program.
These statements can be used inside loops, switch statements and in methods to move the next execution to some other expression. break can be used to exit a loop or to come out of the switch statement or to use as a form of goto. continue can be used inside a loop to skip the current iteration. return can be used to explicitly return from a method.
/* Factorial.java */
import java .util. Scanner;
public class Factorial
{
public static void main (Strings args[ ] )
{
Scanner keyboard= new Scanner (System.in);
int factorial= 1 ;
System.out.print( " 5 : 5 ) ;
int num = keyboard.nextInt ( ) ;
while ( 5 > 0 )
{
factorial * = num;
num- - ;
}
System.out.println ( Factorial is:" + factorial);
keyboard.close
}
}