i used .next() in my program and when i type a sentence with a spacing it goes to the next line with another prompt sentence anyone knows why?
i will upload screenshots of the problem i have.
sentence without spacing:
sentence with spacing:
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i used .next() in my program and when i type a sentence with a spacing it goes to the next line with another prompt sentence anyone knows why?
i will upload screenshots of the problem i have.
sentence without spacing:
sentence with spacing:
I think this is because you are using .next() and that reads the first word only. Try .nextLine()
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
i figured it out when i put this static Scanner myScanner = new Scanner(System.in).useDelimiter("\r\n"); it works any idea what the .useDelimiter does?
A delimiter is a character that identifies the beginning or the end of a character String.
Delimiter - Wikipedia, the free encyclopedia
If for example you have a comma in your sentance, you can set the delimiter to comma and split the sentance at that point.
I would still recommend using myScanner.nextLine(); though.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
i tried using nextLine but it also skips to another line