How to accept user input in Java ⌨️【8 minutes】
Вставка
- Опубліковано 13 жов 2024
- 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
Agree
Agree
Agree
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
Yeah!!!!!!!!!!!!!!!!!!!!!!!
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!
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
Just started this course...super excited to finish it ❤😊
May God bless you, its has been hard since I started college. Now I can Understand better!!!
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!
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.
Best teacher for beginners and intermediate 🎉🎉🎉
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
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
if this guy isn't the best teacher in the world idk who is
LOVE YOU BRO
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.
Your explanations and examples is very clean and easy to learn. Thank you so much for your effort
I hope you will get more than 1M views each time you uploaded a new video after one day, in the future.
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
❤❤❤❤❤❤❤❤❤❤❤❤❤❤
You made it so simple & super 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 ...
You are the best programming channel!
Dude your tutorials are the best
this is a comprehensive explanation
this is what i did on my own after watching
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.println("Whats your name?");
String name = x.nextLine();
System.out.println("Whats your age?");
int agr = x.nextInt();
x.nextLine();
System.out.println("Whats your favourite food");
String food = x.nextLine();
System.out.println("Hello "+ name);
System.out.println("You are " + agr + " yrs old");
System.out.println("Your favourite food is "+ food);
}
}
its a little confusing since its not as user friendly as pyton and java but your videos help quite a bit.
Great explanation of the mysterious behavior of the Scanner class.
Thank you so much for this playlist! I'm currently reviewing for our Algorithms class, bro and I totally forgot about it all 😭😭😭
Great tutorial. I like seeing how much java differs from python, which is the tutorial language I learned in school.
Finally, get this tutorial that explained this error clearly
Short ☑️
Useful ☑️
Practical ☑️
Life Changing ☑️
best java course!
The shia Labeouf "Just do it" icon made me subscribe. Thanks bro
You are a life saver THANK YOU
Man! You saved my java project! Thank you!
your videos ara just incredible
Thanks, Bro!! /n explanation was what I was looking for throughout the youtube
Excellent Bro ♥️ , You've earned a couple of subscribers!
Thank you for giving us such a great learning material !:)
Very important video of Java for input data by user with keyboard.
I'm from Jordan, thank's u Bro code u'r professional
Love your style bro!
Bro is the realest of all bros
you are a true gigaChad programmer bro!!!
Excuse me, Mr. Bro. Great tutorials you have here, but could you please make more videos about using pygame? I think it would be fun for people who have mastered Python or at least have an intermediate knowledge of the language. Thank you.
I miss C so much 😭
wow brother wow very good realy
Thank you for the great video! Keep up the good work!
a perfect reviewr ty my dude
This is epiccccccccccccccccccccccc loving this.............
Nice and smoothly explained
Super as usually!!
Great tutirial ever !!!!!
Bro is always here for me.
Thank you Bro ❤️❤️❤️
You are the best bro !!
Da best bro in Da entire world
Αυτό είναι ένα σχόλιο για το συγκεκριμένο βίντεο. Τι αλγόριθμος και πράσινα άλογα... Αφού ήρθαν οι Έλληνες μη φοβάσαι 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
your videos are so useful, thank you
You are simply great, Bro!
Jesus, you are the best man! I discover your channel today!
found it very helpful
Hey Bro,I have a question from my school I have an image where can I send the image?Please clarify my doubt of menu based programs🙏
Hey bro really love your videos!
I just have a question, I think there's a small mistake at 4:28 or at least something that i couldn't get - so you said that this common problem happens if you use .nextLine after .nextint or anything else that's not .nextLine, but how is that possible since if you add .nextLine it does cause a problem? and i assume you do answer what you can add after .nextint I just didn't get there.
Thank you very much in advance!
He said the problem exist if you use nextInt or anything else that isn't nextLine, not the opposite.
Great tutorial bro
Thanks Bro for a great lesson!
You are amazing bro. Thank you so much
Another lesson that i understood
thank for teaching. I learnt from you
Please make a video on Snake Game and tell us why you make 3 different classes?
Why you're putting all details of code in only gamepanel class?
It was helpful thanks❤
good explanation bro
Great tutorial! Thanks!
Thx for video bro !
you are amazing!
thanks for this tutorial bro
this easy learn thanks of course !!!
I just love your voice, @Bro Code !!
Very easy to understand. Thank you :)
Scanner scanner = new Scanner(System.in); -> you could have explained why System.in is passed here. Anyway your tutorials are awesome
Look at the thumbnail though!!😂😂😂😂
good lesson, bro
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?
Great video , thanks for the efforts !!!
incredible video, thank you bro
We can also use
String food =sc.next();
so that the code doesnt skip that question right?
Thank you very much
a lot of prayers to the algorithm!
Thanks. good class
great video bro!!
Nice Work
Amazing
enjoyed!
Great Video, Bro!
great video
Thank You ❣
Thanks for the help on java, I was using a school computer so I couldn't like or comment. I'm doing that now.
Thanks Giga Bro🔥
lovin' it