Hey, plz can u explain what scanner.nextLine() means...
Thanks
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.
Hey, plz can u explain what scanner.nextLine() means...
Thanks
That statement shows a object reference: scanner being used to call a method: nextLine().
To see what that method does, read the API doc for the scanner class.
Java Platform SE 7
If you don't understand my answer, don't ignore it, ask a question.
can u give a real life example of the scanner.nextLine() method please?
it would help me understand it :p
Do a search here on the forum. There are lots of programs that use that method.
If you don't understand my answer, don't ignore it, ask a question.
but can you give me a real life example?
The code posted here on the forum are real life examples of the usage of that method.
If you have any questions about the code you have found and can not get it to compile and execute for testing, copy the copy here and ask any questions you have about it.
If you don't understand my answer, don't ignore it, ask a question.
does scanner mean that you can type stuff?
Scanner scanner1 = new Scanner (System.in);
System.out.println("Can you type?");
scanner1.nextLine() //with this i can type and characters will appear - without this line no characters i type will appear.
Did you read the API doc for the nextLine() method to see what it does? It is a method that returns a String.
Are you talking about what appears on the console window when you type something in?type and characters will appear
The use of the System.in arg in the constructor designates where the Scanner class will get its input from: the keyboard.does scanner mean that you can type stuff?
If you don't understand my answer, don't ignore it, ask a question.
Ok, yes i typed in the console window
and is that a yes for does scanner mean that you can type stuff?
I'm not sure what you mean by "type stuff". When I open a command prompt window, I am able to type stuff into the window. It has nothing to do with java or using the Scanner class.
Using the Scanner class with System.in as its arg means that what the user types into the command prompt window will be read by the Scanner class's methods.
If you don't understand my answer, don't ignore it, ask a question.
Ok, basically when i take away the "scanner1.nextLine()"
characters dont appear in the console when i type them,
If scanner1.nextLine() is added, i can type characters into the console and they will show up.
Interesting. I don't know what use typing characters on the console is.
The useful part is that what is typed on the console can be read into the program and used by the program.
If you don't understand my answer, don't ignore it, ask a question.
I use eclipse to type in the console.
I use the OS's command prompt window.
If you don't understand my answer, don't ignore it, ask a question.