How to get -1 to not be calculated in the program

import java.util.Scanner;

public class FactMore {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

int n=1;

int factorial = factorial(n);

while (n >= 1) {

System.out.print("Enter a non-negative integer (-1 to quit) : ");

n = keyboard.nextInt();

factorial = factorial(n);

System.out.println(n + "! = " + factorial);}

if (n == 0) {

System.out.print(n = 1); }

if (n == -1) {

System.out.print("Goodbye!"); }

}

public static int factorial(int n) {

int factorial = 1;

for(int i = 1; i <= n; i++) {

factorial = factorial * i; }

return factorial;

}

}

I am writing a program that repeatedly calculates the factorial of the imputed number, and it...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts