扫描仪变得疯狂,而不是首先在循环中工作

时间:2016-01-03 23:13:02

标签: java eclipse while-loop hashmap java.util.scanner

好的解释我的问题是什么发生了

while (TimeLineSpace > 0) {
        System.out.println("What would you like event " + Changer + "     To say");
        System.out.println("Currently Editing Event " + Changer +   "..." );
        String ScanResult4 = Scan.nextLine();
        TimeLineInfo.put(Changer, ScanResult4);
        TimeLineSpace--;
        Changer++;

在这段代码中(将在最后显示完整的程序)我试图让程序峰值超时HashMap值,它会在不同的键中运行。然而,当我运行它(显示控制台)时会发生什么

What would you like event 1 To say
Currently Editing Event 1...
What would you like event 2 To say
Currently Editing Event 2... 
//This part is not in console and right here though is a Scanner input which works

所以总结一下我的问题它会跳过第一个扫描器输入只到第二个等等,我不知道为什么我尝试用get()显示1的值;然而,它没有返回任何东西,因为它跳过了它没有给它任何价值很好的现在显示整个事情以获得更好的理解非常感谢你,如果你可以帮助

package learning;

import java.util.HashMap;
import java.util.Scanner;

public class TimeLine {
public static void main(String[] args) {

    System.out.println("Welcome to a custom timeline");
    System.out.println("What would you like to call your timeline");
    Scanner Scan = new Scanner(System.in);

    String ScanResult1 = Scan.nextLine();

    System.out.println("We will now bring you to the edit section");

    System.out.println("What would you like as the beg. of timeline");
    int ScanResult2 = Scan.nextInt();

    System.out.println("What would you like as the end of timeline");
    int ScanResult3 = Scan.nextInt();

    int TimeLineSpace = ScanResult3 - ScanResult2;
    System.out.println("You have " + TimeLineSpace + " of space");

    int HigestValue = TimeLineSpace;
    int Finder = HigestValue - 1;
    int Changer = HigestValue - Finder;

    HashMap<Integer, String> TimeLineInfo = new HashMap<Integer, String>();

    while (TimeLineSpace > 0) {
        System.out.println("What would you like event " + Changer + " To say");
        System.out.println("Currently Editing Event " + Changer + "..." );

        String ScanResult4 = Scan.nextLine();

        TimeLineInfo.put(Changer, ScanResult4);

        TimeLineSpace--;
        Changer++;
    }

    Scan.close();

    }
}

0 个答案:

没有答案