
while(console.hasNext()){
String in=console.next();
if(OPERATION_EXIT.equals(in.toUpperCase())
||OPERATION_EXIT.substring(0,1).equals(in.toUpperCase())){
System.out.println("您已成功退出女神信息.");
break;
}else if(OPERATION_GET.equals(in.toUpperCase())
||OPERATION_GET.substring(0,1).equals(in.toUpperCase())
||OPERATION_GET.equals(prenious)){
prenious=OPERATION_GET;
if(step==1){
System.out.println("请输入您要查询的女神[id]");
}else if(step==2){
try {
Goddess g=action.get(Integer.valueOf(in));
System.out.println(g.toString());
}catch (Exception e) {
e.printStackTrace();
System.out.println("您输入的id有误请重新输入!");
step=0;
}
}
step++;兄弟,这个问题解决了吗?我与你遇到相同问题了
首先你的代码有点问题
应该要在try里面加入 step = 0;
在输出查询人的信息之后也要把step至为1
然后你说的那个问题,你输入的那些文字,其实是问你进入哪个功能模块,但是因为OPERATION_GET.equals(prenious)时,就进入了你之前进入的get这个判断里面,所以显得貌似这个输入很没意义,其实也是代码不严谨的问题,如果在查询信息之后就把prenious制空就不会出现这个状况了
id是不是声明为int,可以把Integer.valueOf(in)改成Integer.parseInt(in)看看