Java switch ⬇【4 minutes】

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2024
  • Java switch statement
    #Java #switch #statement
    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!");
    }
    }
    }

ความคิดเห็น • 187

  • @BroCodez
    @BroCodez  3 ปีที่แล้ว +101

    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 ปีที่แล้ว +4

      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

      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

  • @Chndnsharma28
    @Chndnsharma28 3 ปีที่แล้ว +121

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

    • @oxi1492
      @oxi1492 11 หลายเดือนก่อน +11

      No main method found in program

    • @Sqrt.Infinity
      @Sqrt.Infinity 9 หลายเดือนก่อน +7

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

    • @deiti
      @deiti 4 หลายเดือนก่อน

      @@Sqrt.Infinity incorrect indentation

  • @KarolKasperek
    @KarolKasperek ปีที่แล้ว +12

    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 3 หลายเดือนก่อน +1

      what will be the default and break for this expression

    • @Fadhelalmalki
      @Fadhelalmalki 22 วันที่ผ่านมา

      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

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 ปีที่แล้ว +11

    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

  • @coltonbailey8873
    @coltonbailey8873 3 ปีที่แล้ว +30

    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.

    • @user-tl3gb5ds8n
      @user-tl3gb5ds8n 9 หลายเดือนก่อน

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

  • @mpathfinder
    @mpathfinder 3 ปีที่แล้ว +9

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

  • @Actionkidfam
    @Actionkidfam ปีที่แล้ว +5

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

  • @epic1343
    @epic1343 3 ปีที่แล้ว +5

    your tutorials are always amazing thanks bro

  • @ItsAkiresuSama
    @ItsAkiresuSama 8 หลายเดือนก่อน +2

    Teachers seeing this and making it 2 hours long:

  • @trebiscott1931
    @trebiscott1931 8 หลายเดือนก่อน

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

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

  • @grozageorge2887
    @grozageorge2887 ปีที่แล้ว +2

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

  • @techaddict5660
    @techaddict5660 3 ปีที่แล้ว +1

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

  • @uuijs1
    @uuijs1 7 หลายเดือนก่อน +1

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

  • @dillonpaul1498
    @dillonpaul1498 ปีที่แล้ว

    Your the best Java Teacher on youtube.

  • @VikasAshok-n4v
    @VikasAshok-n4v 8 วันที่ผ่านมา

    best switch case explanation

  • @sleepypanda8249
    @sleepypanda8249 ปีที่แล้ว +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 :>

  • @elboulifihoussam4769
    @elboulifihoussam4769 2 ปีที่แล้ว +3

    Well explained!

  • @meeh0
    @meeh0 2 ปีที่แล้ว +1

    Thank you so much. Well explained

  • @treezy97
    @treezy97 9 หลายเดือนก่อน

    You teached me alot sir, Thank you!

  • @straightguy8384
    @straightguy8384 ปีที่แล้ว

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

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

  • @user-fy2cn5jr3j
    @user-fy2cn5jr3j หลายเดือนก่อน

    Thanks man
    very much appreciate it

  • @Dev-PauloEd
    @Dev-PauloEd 2 ปีที่แล้ว

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

  • @victortruong1524
    @victortruong1524 ปีที่แล้ว

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

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

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

  • @chikondiphelzmapelera5794
    @chikondiphelzmapelera5794 ปีที่แล้ว +1

    This is really lit bruh🔥🔥

  • @Jack-mr6ty
    @Jack-mr6ty 2 หลายเดือนก่อน

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

  • @tanjirodluffy4403
    @tanjirodluffy4403 7 หลายเดือนก่อน +1

    Thank you bro

  • @honoredegg
    @honoredegg 2 ปีที่แล้ว

    Thank you, Bro Sensei👍

  • @user-qq3ix3py6l
    @user-qq3ix3py6l ปีที่แล้ว

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

  • @anyarasan8529
    @anyarasan8529 10 หลายเดือนก่อน

    you are a hero bro

  • @dllm3tommy741
    @dllm3tommy741 11 หลายเดือนก่อน

    Thanks for the video

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

  • @mohamedelfadli3125
    @mohamedelfadli3125 ปีที่แล้ว

    I like your teaching style. hhhh

  • @gloriouslover100
    @gloriouslover100 7 หลายเดือนก่อน

    good video bro!

  • @mawhadmd
    @mawhadmd ปีที่แล้ว

    well explained

  • @uneducatedguy369
    @uneducatedguy369 6 หลายเดือนก่อน

    Can we apply switch case to integer also ?

  • @mishabalakirsky243
    @mishabalakirsky243 วันที่ผ่านมา

    Thanks, bro

  • @oximas-oe9vf
    @oximas-oe9vf 2 ปีที่แล้ว

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

  • @JuliHoffman
    @JuliHoffman 2 ปีที่แล้ว

    Great video!

  • @ghoggaliabdou4222
    @ghoggaliabdou4222 3 ปีที่แล้ว

    Thank you again 💙💙

  • @gamesandsoftwares1441
    @gamesandsoftwares1441 2 ปีที่แล้ว

    doing my part for the algorithm

  • @AmberShah786
    @AmberShah786 2 ปีที่แล้ว

    Thank you🙌

  • @MISA-qy4hx
    @MISA-qy4hx ปีที่แล้ว

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

  • @711mobiles
    @711mobiles 3 ปีที่แล้ว

    Switching case the next lesson, default is learning

  • @CartoonTv-zf2qr
    @CartoonTv-zf2qr 2 ปีที่แล้ว

    Yeah I become a hero !!

  • @bartomiejsniadach5795
    @bartomiejsniadach5795 2 ปีที่แล้ว

    Easy! Thank you

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

  • @rexelcier8768
    @rexelcier8768 2 ปีที่แล้ว

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

  • @abadiabadi3205
    @abadiabadi3205 หลายเดือนก่อน

    A legend

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 ปีที่แล้ว

    you are amazing!

  • @Gogito503
    @Gogito503 หลายเดือนก่อน

    Super!

  • @jpm1127
    @jpm1127 ปีที่แล้ว

    Thank you bro code!

  • @Minecarthus
    @Minecarthus 3 ปีที่แล้ว

    I love you chanel !!!

  • @aditipatil3807
    @aditipatil3807 ปีที่แล้ว

    Thanks

  • @salahadinshemsu6186
    @salahadinshemsu6186 ปีที่แล้ว

    Thanks bro

  • @user-zq6yx7of5f
    @user-zq6yx7of5f ปีที่แล้ว

    thank you!

  • @kacpermikulski6012
    @kacpermikulski6012 3 หลายเดือนก่อน

    Ty bro

  • @PoorwayTraning
    @PoorwayTraning ปีที่แล้ว

    thanks

  • @leechurchill1965
    @leechurchill1965 10 หลายเดือนก่อน

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

  • @lilkido3572
    @lilkido3572 2 ปีที่แล้ว

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

  • @Ibraghim
    @Ibraghim ปีที่แล้ว

    Ily so much

  • @techshrish6300
    @techshrish6300 16 วันที่ผ่านมา

    W EXPLANATION 💥

  • @azamato
    @azamato 2 ปีที่แล้ว

    good to know

  • @natethegreat632
    @natethegreat632 2 ปีที่แล้ว

    Thanks, bro. Algorithm comment

  • @solitude_963
    @solitude_963 4 หลายเดือนก่อน

    thankyou Bro

  • @Suraj-rv2dt
    @Suraj-rv2dt ปีที่แล้ว

    ❤❤❤❤❤ great 🎉🎉🎉🎉

  • @bekturasanbekov1979
    @bekturasanbekov1979 ปีที่แล้ว

    thx 4 vid bro

  • @ramakrishnatallapragada7569
    @ramakrishnatallapragada7569 ปีที่แล้ว +1

    Thanku Bro🙏🙏🙏🙏

  • @tamirrozenfeld3572
    @tamirrozenfeld3572 2 ปีที่แล้ว

    THank!

  • @samrusselcanillo127
    @samrusselcanillo127 11 หลายเดือนก่อน

    Thanks Bro code ❤

  • @mzpaige98
    @mzpaige98 3 ปีที่แล้ว

    you are the best.

  • @mayamaya-px2zv
    @mayamaya-px2zv 3 ปีที่แล้ว

    thank u so much

  • @roboticskarawang6132
    @roboticskarawang6132 ปีที่แล้ว

    i though you need to give number for each case

  • @furkanveliisk4113
    @furkanveliisk4113 ปีที่แล้ว

    thanks brah

  • @martinsvanda5874
    @martinsvanda5874 ปีที่แล้ว

    nice

  • @jndahal1477
    @jndahal1477 ปีที่แล้ว

    I did the way you taught. But when I run the program it says "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted" whats wrong?

    • @jayanthbonugu6679
      @jayanthbonugu6679 ปีที่แล้ว

      Me too, can you help me?

    • @mouradjaafar6013
      @mouradjaafar6013 10 หลายเดือนก่อน

      Look what you have to do
      Right click on your project, go to Properties. Select Java Compiler from the left menu. Select your compliance level (1.7 or 1.6). 1.7 will stop that message. 1.6, as others said before, won't let you use strings

    • @furkan809
      @furkan809 10 หลายเดือนก่อน +1

      thank you @@mouradjaafar6013

  • @Abdulaziz-bj5rg
    @Abdulaziz-bj5rg ปีที่แล้ว

    legend

  • @Giovanni-Rhonim
    @Giovanni-Rhonim 7 หลายเดือนก่อน

    God Bless you Bro +7

  • @williamtowne2079
    @williamtowne2079 2 ปีที่แล้ว

    thx

  • @omersond4891
    @omersond4891 3 ปีที่แล้ว

    just switchted to the switch video

  • @leonkr8691
    @leonkr8691 2 ปีที่แล้ว

    good video

  • @wallstreetbets7741
    @wallstreetbets7741 2 ปีที่แล้ว

    thx learnt

  • @huuloc8719
    @huuloc8719 2 ปีที่แล้ว

    Nice.

  • @soumelee5661
    @soumelee5661 ปีที่แล้ว

    pizza is not a day indeed

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

    • @willeam9709
      @willeam9709 3 ปีที่แล้ว

      of course you can!

    • @willeam9709
      @willeam9709 3 ปีที่แล้ว +1

      @levimonarca did you create an array list and add all of the values into that? Sorry I’m just trying to understand

    • @user-np8hd2sc1q
      @user-np8hd2sc1q ปีที่แล้ว

      Hiw?

    • @user-np8hd2sc1q
      @user-np8hd2sc1q ปีที่แล้ว

      How?

  • @javierpesaresi311
    @javierpesaresi311 ปีที่แล้ว

    Like it

  • @cesara9747
    @cesara9747 2 ปีที่แล้ว

    doing well!

  • @danielmilewski7659
    @danielmilewski7659 2 ปีที่แล้ว

    comment for stats. thanks!

  • @yeliza2350
    @yeliza2350 2 ปีที่แล้ว

    4 february done

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 ปีที่แล้ว

    i dunno if i'll switch to eclipse after 2 years of netbeans

    • @voengi
      @voengi 8 หลายเดือนก่อน

      update did you switch?

  • @sagarikasahoo6141
    @sagarikasahoo6141 6 หลายเดือนก่อน

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

  • @mlgcactus1035
    @mlgcactus1035 4 หลายเดือนก่อน

    pro gunga moment here

  • @NebyuDaniel-j6b
    @NebyuDaniel-j6b 6 วันที่ผ่านมา

    😊😊😊

  • @filiprashev6658
    @filiprashev6658 2 ปีที่แล้ว

    cool!

  • @simik4830
    @simik4830 24 วันที่ผ่านมา

    comment for algorithm