How to create error message when negative number is entered in Java factorial

I need to modify this code so that and error message is displayed when a negative number is entered. I know and else statement has to fit in I just can figure out where.

public static void numberFactorial() {

System.out.println("Option 2 selected, enter a number: ");

int number = sc.nextInt();

System.out.println("The factorial is: " + number + " ");

for (int i = 1; i <= number; i++)

{

factorial *= i;

if ((number - 1) > 0)

{

System.out.print("x" + (number - i) + " ");

}

System.out.println("=" + factorial);

}

}

This is the pseudo...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts