【发布时间】:2013-09-12 16:26:56
【问题描述】:
我基本上只是在用户输入零时才尝试结束程序,否则继续循环输入进行处理。
我对发生了什么有疑问,每当我尝试编译它时,它总是给我这样的错误:
预期输出您的输出 1 16 1 线程中的异常 “主”java.util.InputMismatchException 2 汤姆 69.28 2 在 java.util.Scanner.throwFor(Scanner.java:909) 3 米奇 108.42 3 在 java.util.Scanner.next(Scanner.java:1530) 4 朱丽叶 2488.71 4 在 java.util.Scanner.nextInt(Scanner.java:2160) 5 安 2201.94 5 在 java.util.Scanner.nextInt(Scanner.java:2119) 6 克里斯蒂 894.14 6 在 Bank.main(Bank.java:103)
public static void main(String[] args) {
// declare the necessary variables
double x;
int p;
double balance;
String name;
List<Person> list = new ArrayList<Person>();
// declare a Scanner object to read input
Scanner sc = new Scanner(System.in);
// read input and process them accordingly
x = sc.nextDouble();
p = sc.nextInt();
// while (sc.hasNext() == true)
String action;
// {
do {
action = sc.next();
//ArrayList list = new ArrayList();
if (action.equals("Create"))
{
do something
}
if (action.equals("Withdraw"))
{
{
do something
}
}
}
if (action.equals("Deposit"))
{
// output the result
}
if (action.equals("0"))
{
System.out.println(list.size());
for(Person d : list){
double bal = d.getBalance();
System.out.println(d.getName());
} }
}
while ( /*action != null &&*/ !action.isEmpty());
}
}
【问题讨论】:
-
您是否将 x 和 p 分别声明为 double 和 int?
标签: java