?
2013-10-08 11:41:23 UTC
import java.io.*;
import java.util.*;
public class Prog175a
{
public static void main (String[] args)
{
Scanner kbReader = new Scanner(System.in);
System.out.print("Enter a Number [zero to quit]"); //Enter 6
int value1 = kbReader.nextInt();
System.exit(0);
int x = 1;
for(int a = 1; a<=6; a++)
{
x = x*a;
}
System.out.println("The value of 6! is " + x);
System.out.println(" ");
System.out.print("Enter a Number [zero to quit]"); //Enter 9
int value2 = kbReader.nextInt();
System.exit(0)
int d = 1;
for(int c = 1; c<=9; c++)
{
d = d*c;
}
System.out.println("The value of 9! is " + d);
System.out.println(" ");
System.out.print("Enter a Number [zero to quit]"); //Enter 12
int value3 = kbReader.nextInt();
System.exit(0);
int e = 1;
for(int f = 1; f<=12; f++)
{
e = e*f;
}
System.out.println("The value of 12! is " + e);
System.out.println(" ");
System.out.print("Enter a Number [zero to quit]"); //Enter 14
int value4 = kbReader.nextInt();
System.exit(0);
long g = 1;
for(int h = 1; h<=14; h++)
{
g = g*h;
}
System.out.println("The value of 14! is " + g);
System.out.println(" ");
System.out.print("Enter a Number [zero to quit]"); //Enter 0
int value5 = kbReader.nextInt();
System.exit(0);
}
}
If I enter "0" into any of the places where prompted to put a number, then the program should quit. However, I don't know where to put this command. I tried placing it in different spots, but it never worked (The code above shows where I placed System.exit(0) when I first wrote the program). It either continues to run the program or terminates the program when I don't want it to terminate. Could someone please help me with this?
Thanks in advance.