0

I'm stuck on this Scanner code can you help me? Particularly on the line String color = userInput.nextline();

import java.util.Scanner; public class Program{ public static void main(String[] args) { Scanner userInput = new Scanner (System.in); //initializes scanner System.out.println("What is your favorite color"); //user inputs color String color = userInput.nextline(); System.out.println(color + " " + "That is a lovely color!"); //prints out statement } }

19th May 2017, 11:46 AM
Sheri
Sheri - avatar
4 Antworten
+ 19
Well, it should be String color = userInput.nextLine(); // l uppercased :)
19th May 2017, 12:05 PM
Dev
Dev - avatar
+ 11
Use capital L for nextLine() :)
19th May 2017, 12:06 PM
Shamima Yasmin
Shamima Yasmin - avatar
0
Thanks so much. I really don't understand the error messages they're so vague.
19th May 2017, 12:44 PM
Sheri
Sheri - avatar
0
A 'color' is what I would expect a user to input, but any answer works. Is there a way to limit the answer to colors
19th May 2017, 12:57 PM
Sheri
Sheri - avatar