Java switch ⬇【4 minutes】

Поделиться
HTML-код
  • Опубликовано: 18 окт 2020
  • 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!");
    }
    }
    }
  • НаукаНаука

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

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

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

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

    • @oxi1492
      @oxi1492 9 месяцев назад +10

      No main method found in program

    • @Sqrt.Infinity
      @Sqrt.Infinity 7 месяцев назад +5

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

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

      @@Sqrt.Infinity incorrect indentation

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

  • @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 Месяц назад

      what will be the default and break for this expression

  • @mpathfinder
    @mpathfinder 3 года назад +8

    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

  • @coltonbailey8873
    @coltonbailey8873 3 года назад +29

    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 8 месяцев назад

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

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

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

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

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

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

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

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

    Thank you so much. Well explained

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

    Your the best Java Teacher on youtube.

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

    Love ur videos bro :>

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

    You teached me alot sir, Thank you!

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

    I always come back to this channel to learn anything

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

    Well explained!

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

    This is really lit bruh🔥🔥

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

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

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

    Thank you, Bro Sensei👍

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

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

    Great video!

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

    Thank you again 💙💙

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

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

  • @user-fy2cn5jr3j
    @user-fy2cn5jr3j 3 дня назад

    Thanks man
    very much appreciate it

  • @dllm3tommy741
    @dllm3tommy741 9 месяцев назад

    Thanks for the video

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

    good video bro!

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

    you are a hero bro

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

    Thank you🙌

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

    you are amazing!

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

    Thank you bro

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

  • @Dev-PauloEd
    @Dev-PauloEd 2 года назад

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

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

    thank you!

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

    well explained

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

    Easy! Thank you

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

    I love you chanel !!!

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

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

  • @grozageorge2887
    @grozageorge2887 Год назад +2

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

  • @mayamaya-px2zv
    @mayamaya-px2zv 2 года назад

    thank u so much

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

    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.

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

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

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

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

  • @ItsAkiresuSama
    @ItsAkiresuSama 6 месяцев назад +2

    Teachers seeing this and making it 2 hours long:

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

    you are the best.

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

    Ty bro

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

    Ily so much

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

    Thanks bro

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

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

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

    thx 4 vid bro

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

    Thank you bro code!

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

    ty bro

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

    Thanku Bro🙏🙏🙏🙏

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

  • @oximas-oe9vf
    @oximas-oe9vf Год назад

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

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

    Can we apply switch case to integer also ?

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

    thanks

  • @711mobiles
    @711mobiles 3 года назад

    Switching case the next lesson, default is learning

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

    I like your teaching style. hhhh

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

    good video

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

    thanks brah

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

    THank!

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

    Thanx bro

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

    Thanks Bro code ❤

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

    thankyou Bro

  • @Suraj-rv2dt
    @Suraj-rv2dt Год назад

    ❤❤❤❤❤ great 🎉🎉🎉🎉

  • @Abdulaziz-bj5rg
    @Abdulaziz-bj5rg Год назад

    legend

  • @CartoonTv-zf2qr
    @CartoonTv-zf2qr 2 года назад

    Yeah I become a hero !!

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

    Nice.

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

    nice

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

    thx

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

    cool!

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

    good to know

  • @Jack-mr6ty
    @Jack-mr6ty Месяц назад

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

  • @Giovanni-Rhonim
    @Giovanni-Rhonim 6 месяцев назад

    God Bless you Bro +7

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

    doing my part for the algorithm

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

    doing well!

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

    Like it

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

    merci

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

    thx learnt

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

  • @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 9 месяцев назад

      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 8 месяцев назад +1

      thank you @@mouradjaafar6013

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

    i though you need to give number for each case

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

    Thanks, bro. Algorithm comment

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

    just switchted to the switch video

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

    ❤❤❤

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

    dropped a comment

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

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

    Bro#1

  • @leechurchill1965
    @leechurchill1965 9 месяцев назад

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

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

    ❤‍🔥

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

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

    pro gunga moment here

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

    ❤️👌

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

    4 february done

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

    Thanks Bro!

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

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

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

      update did you switch?

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

    pizza is not a day indeed

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

    my comment bro thank you bro