Hello! Tell me by code that you can still add or alter? the program that calculates the factorial of the natural number n, which the user will enter from the keyboard.
How else can I remove 1 if, for example, I enter a negative number there it gives me "You entered negative factorial!", But it gives 1 over it?
public class Test { public static void main(String args[]) { int n; do { Scanner scan = new Scanner(System.in); System.out.print("Введите факториал натурально числа n : "); n = scan.nextInt(); int result = 1; for (int i = 2; i <= n; i++) result *= i; System.out.println(result); if (n == 0 || n == 1) System.out.println(result); if(n < 0) System.out.println("Вы ввели отрицательный факториал!"); } while (n < 0);{System.out.println("Конец");} } }