Java switch ⬇【4 minutes】

Поділитися
Вставка
  • Опубліковано 3 гру 2024

КОМЕНТАРІ • 197

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

    public class Main {
    public static void main(String[] args) {

    // switch = statement that allows a variable to be tested for equality against a list of values

    String day = "Friday";

    switch(day) {
    case "Sunday": System.out.println("It is Sunday!");
    break;
    case "Monday": System.out.println("It is Monday!");
    break;
    case "Tuesday": System.out.println("It is Tuesday!");
    break;
    case "Wednesday": System.out.println("It is Wednesday!");
    break;
    case "Thursday": System.out.println("It is Thursday!");
    break;
    case "Friday": System.out.println("It is Friday!");
    break;
    case "Saturday": System.out.println("It is Saturday!");
    break;
    default: System.out.println("That is not a day!");
    }

    }
    }

    • @_Anna_Nass_
      @_Anna_Nass_ 3 роки тому +5

      Thank you for always taking the time to put the code in the comments.

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

      @@_Anna_Nass_ he can easily copy and paste lol

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

      @@_Anna_Nass_ because he is smart and helpful

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

      You can write "->" instead of ":" and you don't need now writing break at the end
      switch(day) {
      case "Sunday" -> System.out.println("It is Sunday!");
      case "Monday" -> System.out.println("It is Monday!");
      or
      switch(day) {
      case "Sunday" -> {
      System.out.println("It is Sunday!")
      System.out.println("It's a free day!")
      };
      case "Monday" -> {
      System.out.println("It is Monday!")
      System.out.println("It's not a free day!")
      };
      }
      if you need to run more than 1 command.

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

      Sout enter and only bro code

  • @ItsAkiresuSama
    @ItsAkiresuSama 10 місяців тому +26

    Teachers seeing this and making it 2 hours long:

    • @kadeshramos8083
      @kadeshramos8083 10 днів тому

      real, so much unnecessary words to be included during discussions

  • @chndn_off
    @chndn_off 4 роки тому +149

    System.out.println("Awesome explanation!") ;

    • @oxi1492
      @oxi1492 Рік тому +14

      No main method found in program

    • @Sqrt.Infinity
      @Sqrt.Infinity Рік тому +9

      public class Human
      {
      public static void main(String args[])
      {
      System.out.println("Awesome Explanation!" );
      }
      }

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

      @@Sqrt.Infinity incorrect indentation

    • @mufradr
      @mufradr 16 днів тому

      @@deiti
      public class Human {
      public static void main(String args[]) {
      System.out.println("Awesome Explanation!");
      }
      }

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

    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

  • @KarolKasperek
    @KarolKasperek Рік тому +13

    quick reminder.
    Now you can use lambda expression:
    switch(number) {
    1 -> do something;
    2 -> do something;
    3 -> do something
    }
    instead of
    switch(number) {
    case 1: do something;
    break;
    case 2: do something;
    break;
    case 3: do something
    break;
    }

    • @doggo2821
      @doggo2821 5 місяців тому +1

      what will be the default and break for this expression

    • @Fadhelalmalki
      @Fadhelalmalki 3 місяці тому

      It is not Lambda expression it is called (Lambda-like syntax) .. Lambda is the replication for the anonymous inner class ..but may be we can name as enhanced switch

  • @mpathfinder
    @mpathfinder 3 роки тому +9

    Learning the beginnings of Java in school but the tricks in these tutorials are awesome like: sysout + strg/ctrl + space

  • @coltonbailey8873
    @coltonbailey8873 3 роки тому +32

    You teaches the peaches, for real. Thank you so much for taking the time to create these lessons. You've designed them in such a order, that while I'm learning I can take a new concept that you're teaching me, and apply it with one of your previous lessons easily. Right now I'm creating switch statements while interfacing a GUI. I wish you would have squeezed a video about using getText() though, because Scanner can't be used with JOptionPane apparently x). Thank you for teaching me stuff and things, Proffeser Bro.

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

      (⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠๑⁠˙⁠❥⁠˙⁠๑⁠(⁠ʃ⁠ƪ⁠^⁠3⁠^⁠)(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠๑⁠˙⁠❥⁠˙⁠๑⁠)(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠๑⁠˙⁠❥⁠˙⁠๑⁠)(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)⁠✧⁠*⁠。

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

    Tomorrow i've got a Java exam in school, and this helped a lot. Thanks

  • @epic1343
    @epic1343 4 роки тому +7

    your tutorials are always amazing thanks bro

  • @Actionkidfam
    @Actionkidfam 2 роки тому +5

    An exciting and brief course by bro absolutely amazing may your channel grow big Af

  • @uuijs1
    @uuijs1 10 місяців тому +1

    bro, thank you for everything, you helped me pass my ict subject and make coding fun!

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

    Really love your videos.I need to support you!!!!

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

    Your the best Java Teacher on youtube.

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

    im going to like all your videos. you are saving me. thx bro !!!

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

    I always come back to this channel to learn anything

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

    Love ur videos bro :>

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

    Maaaan you got 170 likes and 0 dislikes this is the proof that you are really really really good i think even a monkey would understand java with your lessons you are too good at explaining it

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

    You teached me alot sir, Thank you!

  • @VikasAshok-n4v
    @VikasAshok-n4v 3 місяці тому

    best switch case explanation

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

    I used to think if statements were useless because switch cases exist, but I now know that switch cases can't check for all types of values.

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

    I don't know what i have to comment, just wanna comment to support this channel tho

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

    Thank you for your efficiency!

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

    Thank you so much. Well explained

  • @RuslanLomaka
    @RuslanLomaka 3 дні тому

    Was debugging one hour, because forgot to add breaks

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

    BRO code !!! You are the chosen one, to be the None Indian UA-cam Teacher :))

  • @Dev-PauloEd
    @Dev-PauloEd 2 роки тому

    the good thing in the switch tag is that we can put another condition inside of it.

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

    This is really lit bruh🔥🔥

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

    THANK YOU homie. My ass had no idea what this was in class today. Saved my ass 30 minutes to rewatching lecture videos lol. I think my professor sucks.

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

    Best channel ever!

  • @amanbts-g4z
    @amanbts-g4z Рік тому

    thank you brother you saved my day🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰😍😍😍😍😌😌😌😌

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

    Thanks man
    very much appreciate it

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

    Thank you, Bro Sensei👍

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

    I’ve been learning Java programming on my end for almost 1 month now, and all of the theoretical concepts and logic understanding is only on top of my head, I’ve got a MacBook, so I’m wondering if you have a recommendation about a program for coding to start with, I’d appreciate it since I tried but they did not work properly (

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

    you are a hero bro

  • @ngenogilbert4061
    @ngenogilbert4061 4 роки тому

    Well explained!

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

    Thanks for the video

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

    Thanks for your explanation Bro ! May I know why it shows default whenever I type Monday with small letter m. how can i solve to show correctly without caring Monday or monday

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

    Great video!

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

    Thanku Bro🙏🙏🙏🙏

  • @gloriouslover100
    @gloriouslover100 10 місяців тому

    good video bro!

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

    Thank you🙌

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

    you are amazing!

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

    Switching case the next lesson, default is learning

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

    Thank you again 💙💙

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

    well explained

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

    Can we apply switch case to integer also ?

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

    Easy! Thank you

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

    I like your teaching style. hhhh

  • @曾毓哲-b1t
    @曾毓哲-b1t Рік тому

    thank you!

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

    A legend

  • @oximas-oe9vf
    @oximas-oe9vf 2 роки тому

    i wonder if python has a similar way for handling multiple conditions

  • @Jack-mr6ty
    @Jack-mr6ty 5 місяців тому

    So can you add 3 together like
    Sunday , Monday and Tuesday
    Instead of putting too many break ;

  • @YuliannCastañeda
    @YuliannCastañeda Місяць тому

    Thanks!

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

    doing my part for the algorithm

  • @CartoonTv-zf2qr
    @CartoonTv-zf2qr 2 роки тому

    Yeah I become a hero !!

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

    you are the best.

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

    I love you chanel !!!

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

    Thank you bro

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

    Thanks, bro

  • @Gogito503
    @Gogito503 3 місяці тому

    Super!

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

    @Bro code While making a simple rock paper scissor program I had a recommendation for a rule switch in netbeans. What is a rule switch how and when should it be used?

  • @shinkansen1907
    @shinkansen1907 18 днів тому

    thanks!

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

    Ily so much

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

    Thank you bro code!

  • @techshrish6300
    @techshrish6300 3 місяці тому

    W EXPLANATION 💥

  • @mayamaya-px2zv
    @mayamaya-px2zv 3 роки тому

    thank u so much

  • @Suraj-rv2dt
    @Suraj-rv2dt Рік тому

    ❤❤❤❤❤ great 🎉🎉🎉🎉

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 роки тому

    Thanks

  • @MISA-qy4hx
    @MISA-qy4hx 2 роки тому

    One more thing you can do instead of having to change the day string value is to ask the user to input the day using scanner. However, my question here is how to implement equalsIgnoreCase here?
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    // switch = statement that allows a variable to be tested for equality against a list of values
    Scanner scanner = new Scanner(System.in);
    String day = scanner.nextLine();
    switch(day) {
    case "Sunday": System.out.println("It is Sunday!");
    break;
    case "Monday": System.out.println("It is Monday!");
    break;
    case "Tuesday": System.out.println("It is Tuesday!");
    break;
    case "Wednesday": System.out.println("It is Wednesday!");
    break;
    case "Thursday": System.out.println("It is Thursday!");
    break;
    case "Friday": System.out.println("It is Friday!");
    break;
    case "Saturday": System.out.println("It is Saturday!");
    break;
    default: System.out.println("That is not a day!");
    }
    }
    }

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

    Thanks bro

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

    System.out.println("you gave one of the best explanation , thank you bro ");

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

    thanks

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

    thx 4 vid bro

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

    Thanks, bro. Algorithm comment

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

    I'm a hero

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

    Thanks Bro code ❤

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

    If I become president, I will make pizza the 8th day of the week.

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

    ty bro

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

    THank!

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

    Nice.

  • @Abdulaziz-bj5rg
    @Abdulaziz-bj5rg 2 роки тому

    legend

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

    good to know

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

    good video

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

    comment for stats. thanks!

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

    just switchted to the switch video

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

    thanks brah

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

    i though you need to give number for each case

  • @hadihiwa5690
    @hadihiwa5690 10 місяців тому

    Thanx bro

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

    For the default statement you should have said "That is not a day, but it should be :))."

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

    How do I do it if I want to pick a random variable in the switch statement?

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

    cool!

  • @Giovanni-Rhonim
    @Giovanni-Rhonim 10 місяців тому

    God Bless you Bro +7

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

    doing well!

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

    What if i type "monday" instead of "Monday".
    How can I ignore the case?

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

      Btw thank u bro I love ur videos. Keep it up!

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

    nice

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

    thx

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

    Like it

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

    could you make it so that it randomly generates a day from a list so that it says a random statement instead of you manually changing it?

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

    in 3:37 seconds of your video why it is sunday! is not displayed
    rest all days except monday and sunday are displayed while the switch is on monday only but else must have been
    displayed but sunday is also in the output....kindly answer my doubt....
    rest explaination were nice but i got a doubt in the above things that i have mentioned..
    kindly clear my doubt bro......

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

    merci