How to accept user input in Java ⌨️【8 minutes】
HTML-код
- Опубликовано: 12 окт 2020
- Java user input scanner
#Java #input #scanner
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What is your name? ");
String name = scanner.nextLine();
System.out.println("How old are you? ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.println("What is your favorite food?");
String food = scanner.nextLine();
System.out.println("Hello "+name);
System.out.println("You are "+age+" years old");
System.out.println("You like "+food);
}
} - Наука
You are the best teacher ever
Agree
// It's good practice to close your scanner when you are done using it. scanner.close();
// I forgot to. So I didn't
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What is your name? ");
String name = scanner.nextLine();
System.out.println("How old are you? ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.println("What is your favorite food?");
String food = scanner.nextLine();
System.out.println("Hello "+name);
System.out.println("You are "+age+" years old");
System.out.println("You like "+food);
scanner.close();
}
}
thanks for giving it in the comments! also mine kept on saying error on the first line.
Umm....I'm having a problem here please
It says error..system cannot be resolved to a variable
This is incredible bro, can't believe that not a lot of people watch this. That is the way to teach people! Keep it up! Love your videos
This channel is the best thing to happen to my GPA since Chegg
Bro you have no idea how long it took me to wonder why I couldn't enter any input with the nextLine after nextInt. You are awesome!!
I just discovered your channel, your way of explaining things without too much fuss and in an easy way is amazing, greetings from Honduras and thanks a lot👻.
That broke down the WHY of scanners for me, rather than "because that's just the way it is." Thank you!
I like how you tackled the newline character stuck in the buffer integrated concept (I would still call it an error). I was taught that the buffer needed to be cleared, and I still do not know how to visualize a buffer.
Your explanations and examples is very clean and easy to learn. Thank you so much for your effort
Sir,u really explained Java much more better than the others ,its really commendable.This is the only channel which explains Java in good ways ,i m from India, big thanks to you
eyyy new bro here, I had been dealing with a lot of difficulties on understanding Java and thanks to you it gave me a on point lesson to different difficulties. Keep it up bro I know that you can help more beginner like me.
Using this series alongside with my uni course , love u bro 👊
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
This tutorial is fantastic! The explanations are clear and concise, making it easy to follow along. I've been struggling with understanding [specific programming concept], but your examples really helped clarify things. Thank you for breaking down complex topics into manageable steps. Looking forward to more videos like this!
for strings , when using scanner , its better to use .next(); instead of .nextLine(); to avoid that error , that worked for me at least .
and i have to say , great video , thanks for the efforts .
this is by far the most beginner friendly , right to the point , including tricks and errors tutorial.
i sincerely thank you bro hahahaha
Thank you!!! I took a note of this :)
Next() keyword won't be able to print the whole text, for like name and tittle at the same time
Thanks , it helped a lot
helped me
thanks
If you use ".next();" instead of ".nextLine();", It will be not possible to type more than one word
Example:
Joker - works fine
Joker pro - error
May God bless you, its has been hard since I started college. Now I can Understand better!!!
Bro really you made it so easy for me
Thanks a lot for that bro
Whenever I get stuck I come to your channel and as always I return with a great happy feeling and also with understanding the concept
❤❤❤❤❤❤❤❤❤❤❤❤❤❤
Just started this course...super excited to finish it ❤😊
Love your style bro!
Thanks, Bro!! /n explanation was what I was looking for throughout the youtube
I hope you will get more than 1M views each time you uploaded a new video after one day, in the future.
Thank you for the great video! Keep up the good work!
You are the best programming channel!
Great tutorial! Thanks!
your videos are so useful, thank you
You made it so simple & super easy to understand. Thank you
if this guy isn't the best teacher in the world idk who is
LOVE YOU BRO
Finally, get this tutorial that explained this error clearly
Man! You saved my java project! Thank you!
Excellent Bro ♥️ , You've earned a couple of subscribers!
Thank you for giving us such a great learning material !:)
Nice and smoothly explained
Best teacher for beginners and intermediate 🎉🎉🎉
Great explanation of the mysterious behavior of the Scanner class.
You are simply great, Bro!
Very easy to understand. Thank you :)
For the first time my code executes without error!! # Thank you so much sir, I love your pattern of writing codes so simple ...
your videos ara just incredible
Bro is always here for me.
Thank you Bro ❤️❤️❤️
Hey Bro! I am from India and only your tutorials helped me learn programming even my main language didn't help, Thanks a lot, I am a kid btw
Jesus, you are the best man! I discover your channel today!
Thanks Bro for a great lesson!
this is a comprehensive explanation
a perfect reviewr ty my dude
Very important video of Java for input data by user with keyboard.
You are amazing bro. Thank you so much
Super as usually!!
Great video , thanks for the efforts !!!
The shia Labeouf "Just do it" icon made me subscribe. Thanks bro
great video bro!!
incredible video, thank you bro
Short ☑️
Useful ☑️
Practical ☑️
Life Changing ☑️
You are the best bro !!
best java course!
Great Video, Bro!
thank for teaching. I learnt from you
Great video! One question. I made a program that has an IF/ELSE statement in it, so depending on the user's input of age, it goes to one or the other. The program continues to ask questions and receive input if the user's input leads to the ELSE statement, but if it leads to the IF (i.e., the statement before the ELSE) statement, it stops taking input. Any idea why?
Thx for video bro !
Thank you so much for this playlist! I'm currently reviewing for our Algorithms class, bro and I totally forgot about it all 😭😭😭
This is epiccccccccccccccccccccccc loving this.............
found it very helpful
It was helpful thanks❤
Great tutorial bro
you are a true gigaChad programmer bro!!!
Great tutirial ever !!!!!
you are amazing!
this easy learn thanks of course !!!
ty bro sm
THANK YOU!
lovin' it
Thanks Giga Bro🔥
Da best bro in Da entire world
thanks for this tutorial bro
Thanks. good class
enjoyed!
I'm from Jordan, thank's u Bro code u'r professional
good lesson, bro
I just love your voice, @Bro Code !!
Thanks bro :)
Thank you Bro!
Thank You ❣
Another lesson that i understood
Thanks❤ for it bro
Great tutorial. I like seeing how much java differs from python, which is the tutorial language I learned in school.
you deserved M views for every video
great video
Nice Work
Really like it
thanks bro :D
Αυτό είναι ένα σχόλιο για το συγκεκριμένο βίντεο. Τι αλγόριθμος και πράσινα άλογα... Αφού ήρθαν οι Έλληνες μη φοβάσαι Bro, η επιτυχία είναι δεδομένη.
Sometimes it does not work or maybe i just missing something in my code after i implement the nextLine() method to eat some extra white space; but yeah its very helpful, Thanks bro
Fellow bro ❤️
Amazing
thank you bro
great!!!
great!
Thanks bro😊
so only when we use the nextInt() method we have to always type nextLine() method on the line below it?
love u bro
Thank you