为什么使用了System.exit(0)仍然无法结束程序?输入0之后循环还会继续
import java.util.*;
public class ICarnegieInfoApplication {
public static void main(String[] args) {
int option=0;
while(true) {
option=getchoice();
if(option!=0) {
display(option);
}
}
}
protected static void display(int option) {
Product pro=new Product();
switch(option) {
case 0:
System.exit(0);
case 1:
pro.getName();
break;
case 2:
pro.getAdress();
break;
case 3:
pro.getNumber();
break;
case 4:
pro.getEmail();
break;
case 5:
pro.getURL();
break;
default:
break;
}
}
protected static boolean isNumber(String str) {
for(int i=0;i<str.length();i++) {
if(Character.isDigit(str.charAt(i))==false)
{
return false;
}
}
return true;
}
protected static int getchoice() {
System.out.print("0 – Quit\r\n" +
"1 – Display name\r\n" +
"2 – Display address\r\n" +
"3 – Display telephone\r\n" +
"4 – Display email\r\n" +
"5 – Display URL\r\n" +
"choice>");
Scanner input=new Scanner(System.in);
String stringOption=input.next();
if(isNumber(stringOption)==false) {
System.out.println("java.lang.NumberFormatException: For input string:"+stringOption);
}
else {
if(Integer.parseInt(stringOption)!=0&&Integer.parseInt(stringOption)!=1&&Integer.parseInt(stringOption)!=2&&Integer.parseInt(stringOption)!=3&&Integer.parseInt(stringOption)!=4&&Integer.parseInt(stringOption)!=5) {
System.out.println("Invalid choice: "+stringOption);}
else {
return Integer.parseInt(stringOption);
}
}
return 0;
}
}
class Product{
Product(){
}
void getName() {
System.out.println("iCarnegie, Inc");
}
void getAdress() {
System.out.println("4615 Forbes Avyenue Pittsburgh, PA 15213-3796");
}
void getNumber() {
System.out.println("1.412.622.2150");
}
void getEmail() {
System.out.println("info@icarnegie.com");
}
void getURL() {
System.out.println("http://www.icarnegie.com");
}
}