计算器问题
这个计算器程序就是如果用户输入“add 5" 就+5, ”mul 5" 就程5, 按“help"就弹出指令信息, 按”reset"就归零, 按“exit"就推出目前我的程序+ - * / 都没问题, 问题就在按help, exit, reset的时候,程序就坏掉了, 希望大家帮我指出问题出在哪了。谢谢
import java.util.Scanner;//Needed for the Scanner class
import *;
import java.util.StringTokenizer;
public class HwTwo
{
public static void main(String[] args)
{
double result=0, number, flag=0;
String a, b, c, i;
char d;
boolean spaceKeyPressed = false;
Scanner keyboard=new Scanner (System.in);
System.out.println("Total is " + result);
do
{
System.out.print("Command? ");
b=keyboard.nextLine();
c=b.trim();
StringTokenizer str = new StringTokenizer(c, "add mul sub");
number=Double.parseDouble(str.nextToken());
if (c.startsWith("a")||c.startsWith("A"))
{
result+=number;
}
else if (c.startsWith("e")||c.startsWith("E"))
{
flag=1;
}
else if (c.startsWith("h")||c.startsWith("H"))
{
System.out.println("add Add an int to total");
System.out.println("exit Exit the program");
System.out.println("help Display this text");
System.out.println("mul Multiply total by an int");
System.out.println("reset Set total to zero");
System.out.println("sub Subtract an int from total");
}
else if (c.startsWith("m")||c.startsWith("M"))
{
result*=number;
}
else if (c.startsWith("r")||c.startsWith("R"))
{
result=0;
}
else if (c.startsWith("s")||c.startsWith("S"))
{
result-=number;
}
System.out.println("total is "+result);
}while (flag==0.0);
}
}