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);
    }
    }
  • НаукаНаука

Комментарии • 249

  • @simrangill5830
    @simrangill5830 3 года назад +61

    You are the best teacher ever

  • @BroCodez
    @BroCodez  3 года назад +86

    // 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 3 года назад +4

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

    • @CS_CHILD
      @CS_CHILD 6 месяцев назад +1

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

  • @pastel1213
    @pastel1213 3 года назад +64

    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 года назад +20

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

  • @meng-junglee9071
    @meng-junglee9071 2 года назад +17

    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 10 месяцев назад +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 года назад +3

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

  • @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.

  • @unalysuf
    @unalysuf Год назад +1

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

  • @SwatiKumari-pl7dg
    @SwatiKumari-pl7dg 10 месяцев назад +1

    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

  • @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.

  • @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

  • @kubapawowski7035
    @kubapawowski7035 4 часа назад

    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!

  • @1jokerpro780
    @1jokerpro780 3 года назад +97

    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 2 года назад +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

  • @cristalpineda4178
    @cristalpineda4178 2 года назад +2

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

  • @muzzammilsabuwala2398
    @muzzammilsabuwala2398 Год назад +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
    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤

  • @sarthak3401
    @sarthak3401 7 месяцев назад +3

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

  • @stanislawunruh9082
    @stanislawunruh9082 2 года назад +1

    Love your style bro!

  • @ajaydalvi1378
    @ajaydalvi1378 Год назад

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

  • @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.

  • @alexandrulolea4631
    @alexandrulolea4631 Год назад

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

  • @doronfeldman5152
    @doronfeldman5152 6 месяцев назад

    You are the best programming channel!

  • @marcinzale
    @marcinzale 3 года назад +1

    Great tutorial! Thanks!

  • @RandomUser_543
    @RandomUser_543 2 года назад

    your videos are so useful, thank you

  • @LincyMcGabby
    @LincyMcGabby 4 месяца назад

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

  • @BahaaMaleb
    @BahaaMaleb 4 месяца назад

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

  • @anamika_deb
    @anamika_deb 3 года назад +2

    Finally, get this tutorial that explained this error clearly

  • @user-ss3dj3hl1x
    @user-ss3dj3hl1x 5 месяцев назад

    Man! You saved my java project! Thank you!

  • @venkat2217
    @venkat2217 2 года назад

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

  • @calm_bloomer1219
    @calm_bloomer1219 2 месяца назад

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

  • @viperproduction6454
    @viperproduction6454 3 года назад

    Nice and smoothly explained

  • @Error77_
    @Error77_ 5 месяцев назад +1

    Best teacher for beginners and intermediate 🎉🎉🎉

  • @user-rs2ks1pb1s
    @user-rs2ks1pb1s Год назад

    Great explanation of the mysterious behavior of the Scanner class.

  • @alifaizi6996
    @alifaizi6996 2 года назад

    You are simply great, Bro!

  • @SirKingCAT
    @SirKingCAT Год назад

    Very easy to understand. Thank you :)

  • @joshuaasukwo
    @joshuaasukwo 8 месяцев назад

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

  • @ihssanenedjaoui1444
    @ihssanenedjaoui1444 5 месяцев назад

    your videos ara just incredible

  • @thelastmuslimsamurai3109
    @thelastmuslimsamurai3109 2 года назад

    Bro is always here for me.
    Thank you 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

  • @suleimandiveriosallum3756
    @suleimandiveriosallum3756 3 года назад

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

  • @alexeybudkovskiy
    @alexeybudkovskiy Год назад

    Thanks Bro for a great lesson!

  • @eboylydz1148
    @eboylydz1148 2 года назад

    this is a comprehensive explanation

  • @souleaterboss2246
    @souleaterboss2246 Месяц назад

    a perfect reviewr ty my dude

  • @medjl6083
    @medjl6083 3 года назад

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

  • @thisisbrewsworld
    @thisisbrewsworld 2 года назад

    You are amazing bro. Thank you so much

  • @likeafallen2620
    @likeafallen2620 11 месяцев назад

    Super as usually!!

  • @fizykanaty1346
    @fizykanaty1346 Год назад

    Great video , thanks for the efforts !!!

  • @bobfarker4001
    @bobfarker4001 Год назад

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

  • @ryannayak5797
    @ryannayak5797 3 года назад +1

    great video bro!!

  • @dogowo
    @dogowo 2 года назад

    incredible video, thank you bro

  • @ilgarvideographer
    @ilgarvideographer Год назад +15

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

  • @elkhanmammadli6267
    @elkhanmammadli6267 Год назад

    You are the best bro !!

  • @pushankarmakar1783
    @pushankarmakar1783 Год назад +1

    best java course!

  • @zacharydavid565
    @zacharydavid565 3 года назад

    Great Video, Bro!

  • @wallstreetbets7741
    @wallstreetbets7741 2 года назад

    thank for teaching. I learnt from you

  • @joshbenjamin1100
    @joshbenjamin1100 Год назад +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?

  • @bekturasanbekov1979
    @bekturasanbekov1979 Год назад

    Thx for video bro !

  • @jesterfield5034
    @jesterfield5034 3 месяца назад

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

  • @animeforever8508
    @animeforever8508 10 месяцев назад

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

  • @aboyiphilippa1136
    @aboyiphilippa1136 4 месяца назад

    found it very helpful

  • @user-nd4tu4vi6d
    @user-nd4tu4vi6d 10 месяцев назад

    It was helpful thanks❤

  • @dawidbudkiewicz4509
    @dawidbudkiewicz4509 Год назад

    Great tutorial bro

  • @Anees-qf8so
    @Anees-qf8so 7 месяцев назад

    you are a true gigaChad programmer bro!!!

  • @icm0320
    @icm0320 4 месяца назад

    Great tutirial ever !!!!!

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    you are amazing!

  • @shanksshaki
    @shanksshaki Год назад

    this easy learn thanks of course !!!

  • @ahmedJm1
    @ahmedJm1 Год назад

    ty bro sm

  • @nighter1254
    @nighter1254 2 года назад

    THANK YOU!

  • @kingkock1
    @kingkock1 2 года назад

    lovin' it

  • @mukandeinc
    @mukandeinc Год назад

    Thanks Giga Bro🔥

  • @RuthWondwossen
    @RuthWondwossen Год назад

    Da best bro in Da entire world

  • @ananthan_sreekumar
    @ananthan_sreekumar 7 месяцев назад

    thanks for this tutorial bro

  • @joshuaraymond4996
    @joshuaraymond4996 2 года назад

    Thanks. good class

  • @karimmuhammad149
    @karimmuhammad149 2 года назад

    enjoyed!

  • @-omarabusnineh5174
    @-omarabusnineh5174 3 года назад +3

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

  • @kirillutsenko9306
    @kirillutsenko9306 2 года назад

    good lesson, bro

  • @thedevbek
    @thedevbek 2 года назад

    I just love your voice, @Bro Code !!

  • @virajhaldar2880
    @virajhaldar2880 2 года назад

    Thanks bro :)

  • @kgsimpt
    @kgsimpt 2 года назад

    Thank you Bro!

  • @Vijay_Isaac
    @Vijay_Isaac Год назад

    Thank You ❣

  • @bartomiejsniadach5795
    @bartomiejsniadach5795 2 года назад

    Another lesson that i understood

  • @trickysachin
    @trickysachin 2 года назад

    Thanks❤ for it bro

  • @JustNeutral14.
    @JustNeutral14. Месяц назад

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

  • @omersond4891
    @omersond4891 3 года назад

    you deserved M views for every video

  • @abkcrazyvideos
    @abkcrazyvideos Год назад

    great video

  • @kidsnkiddi2337
    @kidsnkiddi2337 2 года назад

    Nice Work

  • @quanyufeng579
    @quanyufeng579 2 года назад

    Really like it

  • @user-lx8tl2yv5b
    @user-lx8tl2yv5b 5 месяцев назад

    thanks bro :D

  • @nikitassouvatzis1928
    @nikitassouvatzis1928 2 года назад

    Αυτό είναι ένα σχόλιο για το συγκεκριμένο βίντεο. Τι αλγόριθμος και πράσινα άλογα... Αφού ήρθαν οι Έλληνες μη φοβάσαι 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

  • @panduswaroop2788
    @panduswaroop2788 2 года назад

    Fellow bro ❤️

  • @ismailhossainv1
    @ismailhossainv1 2 года назад

    Amazing

  • @matinmonshizadeh
    @matinmonshizadeh 2 года назад

    thank you bro

  • @Sofia-rg3er
    @Sofia-rg3er 4 месяца назад

    great!!!

  • @eugenezuev7349
    @eugenezuev7349 3 месяца назад

    great!

  • @electroplayer.
    @electroplayer. 10 месяцев назад

    Thanks bro😊

  • @whocares_5577
    @whocares_5577 2 года назад

    so only when we use the nextInt() method we have to always type nextLine() method on the line below it?

  • @StandProudYouAreStrong
    @StandProudYouAreStrong Год назад

    love u bro

  • @AmberShah786
    @AmberShah786 2 года назад

    Thank you