扫描仪即使我使用了正确的.NextLine(),也不会读取字符串

时间:2014-12-17 15:45:04

标签: java

我正在为经过的时间编写一个问题,需要一些帮助测试来查看用户是输入am还是pm。我去了.equalsIgnoreCase();在我的字符串上发现它没有存储它。这是我的代码

public static void elapsedTime()
{
    Scanner reader = new Scanner (System.in);

    System.out.print("Enter the beginning hour: ");
    int startingHour = reader.nextInt();

    System.out.print("Enter the beginning minute(s): ");
    int startingMinutes = reader.nextInt();
    reader.nextLine();

    System.out.print("Enter AM/PM: ");
    String startingAmOrPm = reader.nextLine();


    System.out.print("Enter the ending hour: ");
    int endingHour = reader.nextInt();

    System.out.print("Enter the ending minute(s): ");
    int endingMinutes = reader.nextInt();

    System.out.print("Enter AM/PM:  ");
    String endingAmOrPm = reader.nextLine();
    reader.nextLine();



    System.out.println("");
}

正如我研究的那样,我发现了reader.NextLine(),但这并没有帮助字符串没有值。有人可以帮忙吗?我很感激!

0 个答案:

没有答案