0

ok to explain my problem whats happening is

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++;

Inside this block of code (will show full program at end) Im trying to have the program summit a HashMap value overtime it goes around all in different keys. However what happens is when i run it (showing console)

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

So to sum up my problem it skips the first Scanner input going only to the second and so forth which i have no idea why I have tried showing the value for 1 with a get(); however it returns nothing because it skips it not giving it any value well ill show the whole thing now to get a better understanding thank you so much if you could help

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();

    }
}
Sneh
  • 3,027
  • 2
  • 15
  • 30
kazar4
  • 51
  • 8
  • Your code looks like a beehive :P you should format it properly before posting. – Sneh Jan 03 '16 at 23:17
  • Try changing `Scan.nextLine()` to `Scan.next()`. If that works I'll make an answer so you can accept it. – Sheikh Jan 03 '16 at 23:26
  • Well it worked also if you don't mind could you explain why it would matter if its nextLine or next because I'm still not sure why .next made it work, but if your not sure either then just don't bother... Thank you btw and Sneh this for formatting this i went thru a bunch of edits and ended up needing to delete unneeded ints, and scanners – kazar4 Jan 03 '16 at 23:36

0 Answers0