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);
    }
    }

КОМЕНТАРІ • 271

  • @simrangill5830
    @simrangill5830 3 роки тому +80

    You are the best teacher ever

  • @BroCodez
    @BroCodez  4 роки тому +100

    // 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();
    }
    }

    • @nairaac
      @nairaac 4 роки тому +4

      thanks for giving it in the comments! also mine kept on saying error on the first line.

    • @CS_CHILD
      @CS_CHILD 9 місяців тому +1

      Umm....I'm having a problem here please
      It says error..system cannot be resolved to a variable

  • @pastel1213
    @pastel1213 3 роки тому +69

    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

  • @davidbolduc4378
    @davidbolduc4378 3 роки тому +25

    This channel is the best thing to happen to my GPA since Chegg

  • @meng-junglee9071
    @meng-junglee9071 2 роки тому +16

    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!!

  • @Elvin-ne6qq
    @Elvin-ne6qq Рік тому +2

    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👻.

  • @JuliHoffman
    @JuliHoffman 2 роки тому +4

    That broke down the WHY of scanners for me, rather than "because that's just the way it is." Thank you!

  • @1jokerpro780
    @1jokerpro780 3 роки тому +104

    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

    • @stephaniehernandez3641
      @stephaniehernandez3641 3 роки тому +2

      Thank you!!! I took a note of this :)

    • @paia6447
      @paia6447 2 роки тому +4

      Next() keyword won't be able to print the whole text, for like name and tittle at the same time

    • @ayansiddiqui7383
      @ayansiddiqui7383 2 роки тому

      Thanks , it helped a lot

    • @cubebrick7019
      @cubebrick7019 2 роки тому

      helped me
      thanks

    • @sairos4057
      @sairos4057 2 роки тому +17

      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

  • @sarthak3401
    @sarthak3401 10 місяців тому +3

    Just started this course...super excited to finish it ❤😊

  • @cristalpineda4178
    @cristalpineda4178 3 роки тому +3

    May God bless you, its has been hard since I started college. Now I can Understand better!!!

  • @kubapawowski7035
    @kubapawowski7035 2 місяці тому

    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!

  • @mailiesathare
    @mailiesathare 2 роки тому +6

    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.

  • @Error77_
    @Error77_ 7 місяців тому +1

    Best teacher for beginners and intermediate 🎉🎉🎉

  • @deepthakur14916
    @deepthakur14916 Рік тому +2

    Using this series alongside with my uni course , love u bro 👊

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Рік тому +1

    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

  • @ratnaverma2661
    @ratnaverma2661 Рік тому +1

    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

  • @BahaaMaleb
    @BahaaMaleb 6 місяців тому

    if this guy isn't the best teacher in the world idk who is
    LOVE YOU BRO

  • @danrobinlibunao4475
    @danrobinlibunao4475 2 роки тому +2

    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.

  • @unalysuf
    @unalysuf Рік тому +1

    Your explanations and examples is very clean and easy to learn. Thank you so much for your effort

  • @zxnnightstalker2289
    @zxnnightstalker2289 3 роки тому +10

    I hope you will get more than 1M views each time you uploaded a new video after one day, in the future.

  • @muzzammilsabuwala2398
    @muzzammilsabuwala2398 2 роки тому +1

    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
    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤

  • @LincyMcGabby
    @LincyMcGabby 7 місяців тому

    You made it so simple & super easy to understand. Thank you

  • @joshuaasukwo
    @joshuaasukwo 11 місяців тому

    For the first time my code executes without error!! # Thank you so much sir, I love your pattern of writing codes so simple ...

  • @doronfeldman5152
    @doronfeldman5152 9 місяців тому

    You are the best programming channel!

  • @DANNZIU-kv2sc
    @DANNZIU-kv2sc 2 місяці тому

    Dude your tutorials are the best

  • @eboylydz1148
    @eboylydz1148 2 роки тому

    this is a comprehensive explanation

  • @maddinluv3122
    @maddinluv3122 8 днів тому

    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.

  • @PaulLein-t9m
    @PaulLein-t9m Рік тому

    Great explanation of the mysterious behavior of the Scanner class.

  • @jesterfield5034
    @jesterfield5034 6 місяців тому

    Thank you so much for this playlist! I'm currently reviewing for our Algorithms class, bro and I totally forgot about it all 😭😭😭

  • @JustNeutral14.
    @JustNeutral14. 4 місяці тому

    Great tutorial. I like seeing how much java differs from python, which is the tutorial language I learned in school.

  • @anamika_deb
    @anamika_deb 3 роки тому +2

    Finally, get this tutorial that explained this error clearly

  • @ilgar.mp4
    @ilgar.mp4 Рік тому +15

    Short ☑️
    Useful ☑️
    Practical ☑️
    Life Changing ☑️

  • @pushankarmakar1783
    @pushankarmakar1783 Рік тому +1

    best java course!

  • @bobfarker4001
    @bobfarker4001 Рік тому

    The shia Labeouf "Just do it" icon made me subscribe. Thanks bro

  • @soapeated
    @soapeated 17 днів тому

    You are a life saver THANK YOU

  • @UnknownPerson-t7p
    @UnknownPerson-t7p 8 місяців тому

    Man! You saved my java project! Thank you!

  • @ihssanenedjaoui1444
    @ihssanenedjaoui1444 8 місяців тому

    your videos ara just incredible

  • @ajaydalvi1378
    @ajaydalvi1378 Рік тому

    Thanks, Bro!! /n explanation was what I was looking for throughout the youtube

  • @venkat2217
    @venkat2217 2 роки тому

    Excellent Bro ♥️ , You've earned a couple of subscribers!

  • @calm_bloomer1219
    @calm_bloomer1219 4 місяці тому

    Thank you for giving us such a great learning material !:)

  • @medjl6083
    @medjl6083 3 роки тому

    Very important video of Java for input data by user with keyboard.

  • @-omarabusnineh5174
    @-omarabusnineh5174 3 роки тому +3

    I'm from Jordan, thank's u Bro code u'r professional

  • @stanislawunruh9082
    @stanislawunruh9082 3 роки тому +1

    Love your style bro!

  • @Techtinkerer3D
    @Techtinkerer3D Місяць тому

    Bro is the realest of all bros

  • @Anees-qf8so
    @Anees-qf8so 10 місяців тому

    you are a true gigaChad programmer bro!!!

  • @sharkington7007
    @sharkington7007 2 місяці тому

    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.

  • @reynanlamsen2007
    @reynanlamsen2007 3 місяці тому +5

    I miss C so much 😭

  • @RahmatullahVahdatWithCod-pl2vh
    @RahmatullahVahdatWithCod-pl2vh 3 місяці тому +1

    wow brother wow very good realy

  • @alexandrulolea4631
    @alexandrulolea4631 Рік тому

    Thank you for the great video! Keep up the good work!

  • @souleaterboss2246
    @souleaterboss2246 4 місяці тому

    a perfect reviewr ty my dude

  • @animeforever8508
    @animeforever8508 Рік тому

    This is epiccccccccccccccccccccccc loving this.............

  • @viperproduction6454
    @viperproduction6454 3 роки тому

    Nice and smoothly explained

  • @likeafallen2620
    @likeafallen2620 Рік тому

    Super as usually!!

  • @icm0320
    @icm0320 6 місяців тому

    Great tutirial ever !!!!!

  • @thelastmuslimsamurai3109
    @thelastmuslimsamurai3109 2 роки тому

    Bro is always here for me.
    Thank you Bro ❤️❤️❤️

  • @elkhanmammadli6267
    @elkhanmammadli6267 Рік тому

    You are the best bro !!

  • @RuthWondwossen
    @RuthWondwossen Рік тому

    Da best bro in Da entire world

  • @nikitassouvatzis1928
    @nikitassouvatzis1928 3 роки тому

    Αυτό είναι ένα σχόλιο για το συγκεκριμένο βίντεο. Τι αλγόριθμος και πράσινα άλογα... Αφού ήρθαν οι Έλληνες μη φοβάσαι Bro, η επιτυχία είναι δεδομένη.

  • @jaylordjl6337
    @jaylordjl6337 2 роки тому

    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

  • @RandomUser_543
    @RandomUser_543 2 роки тому

    your videos are so useful, thank you

  • @alifaizi6996
    @alifaizi6996 2 роки тому

    You are simply great, Bro!

  • @suleimandiveriosallum3756
    @suleimandiveriosallum3756 3 роки тому

    Jesus, you are the best man! I discover your channel today!

  • @aboyiphilippa1136
    @aboyiphilippa1136 7 місяців тому

    found it very helpful

  • @tallapragadamadhaviramalak4540

    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🙏

  • @MrShadow1137
    @MrShadow1137 2 роки тому

    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!

    • @muimeko2774
      @muimeko2774 Рік тому

      He said the problem exist if you use nextInt or anything else that isn't nextLine, not the opposite.

  • @dawidbudkiewicz4509
    @dawidbudkiewicz4509 Рік тому

    Great tutorial bro

  • @alexeybudkovskiy
    @alexeybudkovskiy Рік тому

    Thanks Bro for a great lesson!

  • @thisisbrewsworld
    @thisisbrewsworld 2 роки тому

    You are amazing bro. Thank you so much

  • @bartomiejsniadach5795
    @bartomiejsniadach5795 2 роки тому

    Another lesson that i understood

  • @wallstreetbets7741
    @wallstreetbets7741 2 роки тому

    thank for teaching. I learnt from you

  • @711mobiles
    @711mobiles 3 роки тому

    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?

  • @MoabiSehapi
    @MoabiSehapi Рік тому

    It was helpful thanks❤

  • @legendtenzy597
    @legendtenzy597 День тому

    good explanation bro

  • @marcinzale
    @marcinzale 3 роки тому +1

    Great tutorial! Thanks!

  • @bekturasanbekov1979
    @bekturasanbekov1979 Рік тому

    Thx for video bro !

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 роки тому

    you are amazing!

  • @ananthan_sreekumar
    @ananthan_sreekumar 9 місяців тому

    thanks for this tutorial bro

  • @shanksshaki
    @shanksshaki Рік тому

    this easy learn thanks of course !!!

  • @beksaylor
    @beksaylor 2 роки тому

    I just love your voice, @Bro Code !!

  • @SirKingCAT
    @SirKingCAT 2 роки тому

    Very easy to understand. Thank you :)

  • @WorkSmarter__
    @WorkSmarter__ 3 роки тому +3

    Scanner scanner = new Scanner(System.in); -> you could have explained why System.in is passed here. Anyway your tutorials are awesome

  • @huseinrahiym463
    @huseinrahiym463 4 роки тому +5

    Look at the thumbnail though!!😂😂😂😂

  • @kirillutsenko9306
    @kirillutsenko9306 2 роки тому

    good lesson, bro

  • @joshbenjamin1100
    @joshbenjamin1100 2 роки тому +1

    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?

  • @fizykanaty1346
    @fizykanaty1346 Рік тому

    Great video , thanks for the efforts !!!

  • @dogowo
    @dogowo 2 роки тому

    incredible video, thank you bro

  • @mahdirahman9970
    @mahdirahman9970 8 місяців тому

    We can also use
    String food =sc.next();
    so that the code doesnt skip that question right?

  • @DixeyDo
    @DixeyDo 29 днів тому

    Thank you very much

  • @cesara9747
    @cesara9747 2 роки тому

    a lot of prayers to the algorithm!

  • @joshuaraymond4996
    @joshuaraymond4996 2 роки тому

    Thanks. good class

  • @ryannayak5797
    @ryannayak5797 3 роки тому +1

    great video bro!!

  • @kidsnkiddi2337
    @kidsnkiddi2337 2 роки тому

    Nice Work

  • @ismailhossainv1
    @ismailhossainv1 2 роки тому

    Amazing

  • @karimmuhammad149
    @karimmuhammad149 2 роки тому

    enjoyed!

  • @Zacharydvd
    @Zacharydvd 3 роки тому

    Great Video, Bro!

  • @abkcrazyvideos
    @abkcrazyvideos 2 роки тому

    great video

  • @Vijay_Isaac
    @Vijay_Isaac 2 роки тому

    Thank You ❣

  • @dr.oswald5400
    @dr.oswald5400 3 роки тому

    Thanks for the help on java, I was using a school computer so I couldn't like or comment. I'm doing that now.

  • @mukandeinc
    @mukandeinc 2 роки тому

    Thanks Giga Bro🔥

  • @kingkock1
    @kingkock1 2 роки тому

    lovin' it