首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到字段匹配字段

找不到字段匹配字段
EN

Stack Overflow用户
提问于 2014-01-13 06:11:28
回答 1查看 45关注 0票数 0

我的问题是,从用户收集数据的第一个选项没有连接到if语句中的第二个选项(都是粗体)。有人对此有什么建议吗?

代码语言:javascript
复制
Scanner keyboard = new Scanner(System.in);

System.out.println("Please select from the following options:");
System.out.println("1. Enter new Policy");
System.out.println("2. Display summary of policies");
System.out.println("3. Display summary of policies for selected month");
System.out.println("4. Find and display Policy");
System.out.println("0. Exit");

try {
    **int option** = Integer.parseInt(keyboard.nextLine());
} catch (NumberFormatException e) {
    System.out.println("Error : program closing");
    System.exit(0);
}

if **(option == 1)** {
    System.out.println("Please enter full name: ");
    String name = keyboard.nextLine();

    while (name.length() >= 21) {
        System.out.print("Name is invalid, please re enter:");
        name = keyboard.nextLine();
    }
EN

回答 1

Stack Overflow用户

发布于 2014-01-13 06:39:16

以下是我将如何做,修改以适应您自己的规范。

代码语言:javascript
复制
public static void Options_() {

   select_option();// Here you invoking the list of options available 

       Scanner keyboard = new Scanner(System.in);
       int number = keyboard.nextInt();

    if (number == 1) {
         //Do something here        

   } else 

        if (number == 2) {
        // Do Something Else        

  }
       //and So on
  }
      public static void select_option() {
      System.out.println("Please select from the following options:");
      System.out.println("1. Enter new Policy");
      System.out.println("2. Display summary of policies");
      System.out.println("3. Display summary of policies for selected month");
      System.out.println("4. Find and display Policy");
      System.out.println("0. Exit");
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21080950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档