当输入中文用户名之后输入年龄就没反应了
代码就算是粘贴过来的也是这样,输入姓名时用中文,然后输入年龄比如"21",之后就无法输入了也没有提示信息。。。有没有大神解救一下
代码就算是粘贴过来的也是这样,输入姓名时用中文,然后输入年龄比如"21",之后就无法输入了也没有提示信息。。。有没有大神解救一下
2016-01-06
package com.view; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Scanner; import com.action.Action; import com.model.Goddess; public class View { private static final String CONTEXT="欢迎来到女神禁区:\n" + "下面是女神禁区的功能列表:\n" + "[MAIN/M]:主菜单\n" + "[QUERY/Q]:查看全部女神的信息\n" + "[GET/G]:查看某位女神的详细信息\n" + "[ADD/A]:添加女神信息\n" + "[UPDATE/U]:更新女神信息\n" + "[DELETE/D]:删除女神信息\n" + "[SEARCH/S]:查询女神信息(根据姓名、手机号来查询)\n" + "[EXIT/E]:退出女神禁区\n" + "[BREAK/B]:退出当前功能,返回主菜单"; private static final String OPERATION_ADD = "add"; private static final String OPERATION_QUERY ="query"; private static Scanner input; public static void main(String[] args) { input = new Scanner(System.in); System.out.println(CONTEXT); Goddess goddess = new Goddess(); Integer step = 1; Action action = new Action(); String previous = null; while(input.hasNext()){ String in = input.nextLine().toString(); if(in.equals("EXIT")){ System.out.println("已退出"); break; }else if(OPERATION_QUERY.equals(in) ||OPERATION_QUERY.substring(0,1).equals(in)){ try { List<Goddess> gs = action.query(); for(Goddess g : gs){ System.out.println(g); } } catch (Exception e) { e.printStackTrace(); } }else if(OPERATION_ADD.equals(in.toLowerCase()) ||OPERATION_ADD.substring(0,1).equals(in.toLowerCase()) ||OPERATION_ADD.equals(previous) ){ previous = OPERATION_ADD; if(1 == step){ System.out.println("请输入姓名:"); }else if(2 == step){ goddess.setUser_name(in); System.out.println("请输入年龄"); }else if(3 == step){ Integer age = Integer.parseInt(in); goddess.setAge(age); System.out.println("请输入生日:yyyy-MM-dd"); }else if(4 ==step){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = null; try{ birthday = sdf.parse(in); goddess.setBirthday(birthday); }catch(ParseException e){ e.printStackTrace(); System.out.println("格式有误"); step=3; } System.out.println("请输入邮箱"); }else if(5 == step){ goddess.setEmail(in); System.out.println("请输入手机号"); }else if(6 == step){ goddess.setMobile(in); try { action.add(goddess); System.out.println("添加成功"); } catch (Exception e) { e.printStackTrace(); System.out.println("添加失败"); } } if(OPERATION_ADD.equals(previous)){ step++; } } else{ step = 1; System.out.println("您输入的值为:"+in); } } } }
举报