Exit method
Sometimes your
program can encounter a situation that makes continuing with the program
pointless. In these cases, you can end your program with a call to
the exit method System.exit(0);
if (number = = 0)
{
System.out.println("Error: Division by zero.");
System.exit(0);
}
else
{
answer = total / number;
System.out.println("The answer is " + answer);
} |