Yes. It is nice to check these cases out in advance before you start writing the program.
Here is a start to the program.
import java.util.Scanner;
// User enters integer N.
// The program calculates N factorial.
//
class factorial
{
public static void main (String[] args )
{
Scanner scan = new Scanner( System.in );
long N, fact = 1;
System.out.print( "Enter N: " );
N = scan.nextLong();
if ( )
{
while ( )
{
;
;
}
System.out.println( "factorial is " + fact );
}
else
{
System.out.println("N must be zero or greater");
}
}
}
Notice how the program matches the flowchart,
especially how the while statement is
nested in the true branch of the if statement.
The indenting (and the braces {} show this structure).
Fill in the four blanks to complete the program. Here are some phrases you might use:
N >= 0 N > 1 N = N - 1 fact = fact*N