How to swap 2 variables (real life example) 🥤

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • Java switch/swap two variables
    #Java #switch #swap #variables

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

  • @BroCodez
    @BroCodez  4 года назад +132

    Drinking game: Take a drink everytime I say the word 'VaRiAbLe'
    //************************************************
    public class Main {
    public static void main(String[] args) {

    String x = "water";
    String y = "Kool-Aid";
    String temp;

    temp = x;
    x=y;
    y=temp;

    System.out.println("x: "+x);
    System.out.println("y: "+y);
    }
    }
    //************************************************

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

      I know I'm late to party
      But me after drinking game: String Result = 1:32

  • @haroldw2823
    @haroldw2823 3 года назад +202

    Dude that visual representation of switching content was the best I've seen.
    It actually has me thinking about programming in a different way now.
    Well done mate!!!!

  • @treebit
    @treebit 4 года назад +279

    That's what I call visualisation!

  • @user-mu3nv7xx2l
    @user-mu3nv7xx2l 3 года назад +69

    This is the most obvious explanation for beginners I've ever seen. Thank you, bro!

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

    Visual teaching is always great, its even better when the visuals are funny!

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

    Today, I start learning OOP in Java. Thank you so much for this free course. I will comment on every video I have learned.

  • @laylachisom8996
    @laylachisom8996 Год назад +10

    It’s not very often I find a teacher I understand on RUclips for Java , but I now have
    Thanks for making it easy to understand!!

  • @nailpluckers
    @nailpluckers 3 года назад +63

    int a = 10, b = 20;
    int temp = 0 ;
    temp = a ;
    a = b ;
    b = temp;
    System.out.println(" The value of a is : " + a ) ;
    System.out.println(" The value of b is: " + b) ;
    Yay! Swapped the variable! :)

  • @GeoffreyofCastille
    @GeoffreyofCastille 3 года назад +10

    Found your channel looking for help in JavaFX - taking an online college course in Java and my instructor's idea of teaching is assigning a chapter to read, assigning a single program, assigning a quiz....and that's it. Watched your first JavaFX video and decided to start at the top because your videos are 1000% more useful than my class. Subscribed!

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

      I feel you on that. I am currently enrolled in Coding Dojo part time online, and it is the same teaching strategy.
      I am learning more from Coursera and youtube videos 😂

  • @mercycebu2896
    @mercycebu2896 3 года назад +6

    I'm a begginer in java programming and your tutorials helps me a lot♥️

  • @sushantlama9010
    @sushantlama9010 3 года назад +4

    Best explanation in the RUclips history......

  • @rekan_98
    @rekan_98 3 года назад +3

    I have been started studying at the university for 3 years ,but this helped me a lot to understand the swapping logic thanks

  • @drone-Eye
    @drone-Eye 2 года назад +4

    Bro, I had Java-phobia, but thanks to you that's faded. Simply, great work brooooo!!!

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

    public class SwitchingVariables {
    public static void main(String[] args) {
    String Mug = "Coffee";
    String Glass = "Milk";
    String ExtraCup;
    ExtraCup = Mug;
    Mug = Glass;
    Glass = ExtraCup;

    System.out.println("Mug with "+Mug);
    System.out.print("Glass with "+Glass);
    }
    }
    It was very easy to understand when you did the Water and Kool-aid showcase

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

      i like your Variables names

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

    honestly bro ur videos are so helpful learning java because its not being presented as a robot professor who just reads out of the book in all of my courses. def gonna recommend u to all my classmates.

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

    Now I really Understood how Variables are Swapped, Thanks for the Real Life Explanation.

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

    Thank Bro Code.
    I could learn java code in English.
    Step by step , I will watch your video in japan.

  • @AP.3.
    @AP.3. 2 года назад +2

    public static void main(String[] args) {
    String x = "Lemon";
    String y = "Water";
    String temp = null; // extra string for switching manually

    temp =x; //pour x into null glass
    x = y; //pour y into x This helps us switch x and y
    y = temp; // pour temp into y
    System.out.println("a: "+y); //use println for printing 2 seperate sentences
    System.out.println("b: "+x);

  • @chunmaroo
    @chunmaroo 4 года назад +6

    I'm still have a bunch of school homework now. after all of these, I will watch your newest java tutorials 😊

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

    Awesome teaching technique - use of a real life illustration that people can relate to. Nice!
    Empty the contents of cup X into cup TEMP, now cup X is empty.
    Empty the contents of cup Y into cup X, now cup Y is empty.
    Empty the contents of cup TEMP into cup Y, now cup TEMP is empty & cups X & Y are full.

  • @Google_Engineer
    @Google_Engineer 3 года назад +3

    Wow!! Godfather of youtube Teachers ,♥️🙏

  • @aryanmauryamr.perfect1426
    @aryanmauryamr.perfect1426 Год назад

    World's best teacher 🙃☺️☺️☺️☺️☺️ real life examples 😅🤘🤘

  • @m.s.mehedihasan
    @m.s.mehedihasan 3 года назад +4

    you are so good as a teacher. I am loving your tutorial.

  • @rohitgiri9266
    @rohitgiri9266 3 года назад +3

    I like the way of you Teach!❤❤😍😍 - Love Programming

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

    Sorry about your floor, Bro. This visualization actually made sense! Thank you!!!

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

    Awesome, cool in style and teaching method.

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

    Here's my example how I practiced it today:
    public class VariableSwitch {
    public static void main(String[] args) {
    String x = "Catfood";
    String y = "Dogfood";
    String temp = null;
    x = temp;
    x = y;
    y = temp;
    System.out.println("x:" + x);
    System.out.println("y:" + y);
    }
    }
    Just basic sh but you still helped me out a lot. Thank you

  • @sankartechpro
    @sankartechpro 4 года назад +4

    Really awesome with real world examples. You're super.

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

    you're one of those GOATED teacher! Love you!!

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

    something that helps me is writing comments describing whats happening when i set a variable equal to something.
    For example:
    temp = x; //temp is set to the value of x(water)
    x = y; //x is set to the value of y(kool-aid)
    y = temp; // y is set the value of temp(water) NOTE: remember temp was set to x which is the value of water

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

    thank you so much I am watching one lesson every day 🤓, trying to learn java from your videos ,keep it up 👍

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

    My brain just melted from this very simple demonstration... A new window has opened for me.

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

    Such a great visual expression.

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

    At first, I really needed to think about it, but I got it when I realized that the programm is executed line by line and that the variables therefore can be redefined depending on the (time)line the programm has progressed to (if that makes any sense). I think one can gets confused because in math, a variable is always fix (at least what I know from school math). I don´t have programming experience myself, I am just trying to find a language to start with by looking through some tutorials. Nice explaination!

  • @CPawnch
    @CPawnch 6 дней назад

    Thanks for another video Bro! I'm still quite new to this so I don't understand the purpose of switching variables. Hoping to learn more and answers as I watch your videos!

  • @husein_alfil
    @husein_alfil 3 года назад +3

    Amazing genius explaining !! Keep that great method !
    I subscribed 2 times 😄

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

    u r such a bro, and I simply don't get tired to spam your comments with appreciation

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

    really loved your way of teaching!

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

    Bro you are awesome and a lot of fun to study with!

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

    that visual representation was genius bro

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

    I think I understood the assignment.
    public class Main {
    public static void main(String[] args) {

    String x = "Burly";
    String y = "Girly";
    String temp;

    temp = y;
    y=x;
    x=temp;

    System.out.println("x: "+x);
    System.out.println("y: "+y);
    }
    }
    Learning Java next semester. Thanks for the vid.

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

    I had not ever watched that type of wonderful visulation ❤ Amazing 🤝

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

    really loved your way of teaching

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

    Ur teaching was clear and crystal ❤❤

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

    I really liked the way that you swap the variable value with showing live example.

  • @99Hitsugaya
    @99Hitsugaya 3 года назад +2

    Well that live demo was fun :)

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

    you saving lives out here .. thank you "Michael Scott impression"

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

    This is the great explanation I have ever seen👍👍👍
    Good luck

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

    Breathtaking visuals.

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

    Real life example is awesome 🔥

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

    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

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

    int x = 3;
    int y = 4;
    int temp = 0;

    temp = x;
    x = y;
    y = temp;
    temp = 0;

    System.out.println(x + ", " + y);
    Thanks for the tutorial!

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

    4 years into computer science and this is the first time that I have ever understood how swapping works for real :)

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

    Uhff Broooo, this is the best variable swapping tutorial I've every seen. I need to come up with this juicy visualization in my class. Never had so much fun by learning a new programming language.👍😎👌

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

    Visual method is the best way to explain something

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

    The best explanation in the globe.

  • @alan-overthenet
    @alan-overthenet 17 дней назад

    Best explanation I have seen

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

    Really liked the kool-aid and water example. Love your vids keep up the good work bro.

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

      thank you for watching Mohammad

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

    I am watching it in March 2024 and found the coolest way to understand.

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

    I so needed this video for my quiz last night. I totally understand it so much better now, thank you!

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

    Your content is pure gold :D

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

    Your tutorials are soo fun to watch and easy to understand i dont understand why you are so underratedd!!

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

    best explantion of the concept ever

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

    thanks for the tutorial
    String x = "Me";
    String y = "Help";
    String temp;
    temp = x;
    x=y;
    y=temp;
    System.out.println("x: "+ x);
    System.out.println("y: "+ y);
    here is the code

  • @user-wr6re2sf7t
    @user-wr6re2sf7t 7 месяцев назад

    Love from bangledesh bro you are doing good i saw your c++ vedio thats helped me a alot in the in my term;

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

    best coding teacher cant express how good he teaches

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

    One of the best course till date for JAVA!

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

    public class Main{
    public static void main(String[] args) {
    int x=14, y=415;
    int s;
    s=x;
    x=y;
    y=s;
    System.out.println(x);
    System.out.println(y);
    }
    }
    You are a great Teacher!!!!!

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

    haven't seen a better teacher in my life

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

    I appreciate the visual demonstration of the code!! good effort thank you

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

    That Real Life Example was really helpful. Thanks

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

    Omg I love this visualization. Can't even mix that logic with this explanation. TYSM.

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

    that real life example is awsome brooo

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

    The explanation is so clear, thank you for your attentively.

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

    Entertaining and mindblowing. Thank you.

  • @HassanGondal-w9e
    @HassanGondal-w9e 5 дней назад

    Great Explanation 😍

  • @Zoid-Berg
    @Zoid-Berg Год назад

    Best visually real life example

  • @python360
    @python360 4 года назад +27

    $ python
    a, b = b, a
    You've been a great audience, goodnight!

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

      that's why I love it and hate it at same time

  • @sk.faizanhussain281
    @sk.faizanhussain281 Месяц назад +1

    I never saw a video LIKE this❤❤❤

  • @Vivekpandey-cy1ul
    @Vivekpandey-cy1ul 3 года назад

    I have not seen any better example like this before.

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

    The visual representation is too good man. 😀; Big Thumps up

  • @user-zl2mb4uw7s
    @user-zl2mb4uw7s Месяц назад

    very interesting explanation

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

    The best ever tutorial 👏👏

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

    Thanks for your real life example with water :)
    It makes me understand more on this swapping method

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

    amazing, simple explanation, thanks bro

  • @somebody.
    @somebody. Год назад

    I am seriously glad I found ur channel!!!

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

    Love the visualization

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

    Love that presentation

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

    i have to say i found this real life example very funny and also helpful

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

    That live example was an overkill 😂

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

    What a visualisation!!

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

    Good idea with the water. I don't even have to try it even once, all I need to know is that the temp is the third glass. Tnx man.

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

    This was a great explanation for how to swap between these variables 👍👍👍👍👍👍👍

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

    I feel like such a menace after coding this:
    String a = "b";
    String b = "a";
    String temp = null;

    temp=a;
    a=b;
    b=temp;

    System.out.println("a: "+a);
    System.out.println("b: "+b);
    And yes, it worked although it was convoluted lol; the output was:
    a: a
    b: b

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

    Thanks for the brilliant video.
    2 people clearly drank the Koolaid....

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

    thx boi(bro with proud feel)!!!😉

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

    You are great can't express in words ❤

  • @ChandraShekhar-Cs238
    @ChandraShekhar-Cs238 2 года назад +1

    good explanation 👌

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

    Became your fan brooooo 😍😍😍
    Love from India ❤️❤️❤️❤️❤️

  • @Momo-iq6uu
    @Momo-iq6uu Год назад

    Best video I've ever seen. You're a genious.