import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static void main(String[] args) { // exception = an event that occurs during the execution of a program that, // disrupts the normal flow of instructions Scanner scanner = new Scanner(System.in); try { System.out.println("Enter a whole number to divide: "); int x = scanner.nextInt(); System.out.println("Enter a whole number to divide by: "); int y = scanner.nextInt(); int z = x/y; System.out.println("result: " + z); } catch(ArithmeticException e) { System.out.println("You can't divide by zero! IDIOT!"); } catch(InputMismatchException e) { System.out.println("PLEASE ENTER A NUMBER OMFG!!!"); } catch(Exception e) { System.out.println("Something went wrong"); } finally { scanner.close(); } } }
@haruamia79312 жыл бұрын
Why use int not double? cant 5/2 with int... try { System.out.println("Enter a whole number to divide: "); double x = scanner.nextDouble(); System.out.println("Enter a whole number to divide by: "); double y = scanner.nextDouble(); double z = x/y; System.out.println("result: " + z); }
@guytordjman71662 жыл бұрын
@@haruamia7931 this will not throw an exception. If y=0 then z is infinity. Arithmetic exception is thrown only when dealing with integer division - give it a try!.
@oscarjosefsson9300 Жыл бұрын
Excuse my but what is the "e" after Exception? Is e an object? Is there any special reason for calling it e? Is there a risk of creating more than one object since e is used for all the catchers?
@dd0n396 Жыл бұрын
@@oscarjosefsson9300 you can name it anything you want. E is just standard
@oscarjosefsson9300 Жыл бұрын
@@dd0n396 Thanks! 👍
@alexshepel55993 жыл бұрын
Your channel is really helpful. Hope you will continue with this. Don't stop, bro!
@jamesarden75543 жыл бұрын
This is by far the best explained java course out there and i have seen loads!!! Concepts i have had trouble with are now no problem thanks to this channel plus i have learned stuff i never even knew java could do
@thewewguy8t88 Жыл бұрын
honestly i thought bucky from the newboston did a decent job as well. granted i never made it past video 40 lol.
@andrevandenheever67403 жыл бұрын
Really like your clear short presentations, thank you. Keep up the good work!
@paulinewachira58394 ай бұрын
I appreciate how you explain the important concepts in a very simple and brief manner. Try block ,catch block and finally.Thank you
@huzaifafaisal50193 жыл бұрын
bro you are so underrated, you cleared things up so much after my lecture
@miyaspapa5628 Жыл бұрын
Clear and concise as always. Thanks bro. You're at 999k subs as of today! Congrats on (inevitably) hitting 1 mil!!!
@cuca3243 Жыл бұрын
You are the best teacher! Now I understand why different exceptions are used.
@stephenbond94872 жыл бұрын
No cap the best straightforward and simple tutorials ever
@Edna_Konrad Жыл бұрын
I really like how basic it all looks like, just for people to understand the concept. Thx bro!
@adityasharma6132 Жыл бұрын
You are really amazing to explain everything. Never stop to make videos!
@skl77143 жыл бұрын
I really love java ..U made it more fun and interesting..THANKS BRO!
@kayleighrenner8293 жыл бұрын
One of my favorite channels for java on KZfaq!!
@gutside80699 ай бұрын
Explained so simply. I really appreciate it. Confidence in Ability to Learn Information . . . Restoring(45%) . . . (99%). . .
@rajneelram42292 жыл бұрын
Appreciate how you explain how to put the exception in blocks, I have been trying to find a decent example of how it works with the code portion. Thank you!
@kristynicole62012 жыл бұрын
Amaaazzzing tutorials, so helpful. Don't stop making tutorials please!
@chillwavefrequency8108 Жыл бұрын
Great videos bro. Love that you cover so much in one Channel. Keep it up Bro!
@vklmao86773 жыл бұрын
Ahhh, a siting at my desk with a coffee ....watching a cool KZfaq video about it......and do not have to go through stacks overflow what else is needed....COOL!!!!😎😎
@eyashamdan43712 ай бұрын
Best teacher on all of KZfaq!!!
@omersond48913 жыл бұрын
very helpful. i never understood these try catch stuff before. finally i understand. thanks ma bro
@Garrison862 жыл бұрын
Thank you Bro code for the amazing tutorials, they are a life saver.
@naledimotsoikha6807 Жыл бұрын
I spent 3hours in class trying to understand this and you do it in 7min52s ... wow you saves me.
@atulgurung6213Ай бұрын
Nicely defined about exception bro, i like the way you teach bro...
@notahmed66823 ай бұрын
i really love the way you explained it, thank you..
@issker88404 ай бұрын
love your vids bro!
@ivanpryhorshnia68542 жыл бұрын
That's quite useful, thanks a lot for a video!
@eyobabebe75362 жыл бұрын
Great explanation, i love the way of teaching , keep doing bro
@rochellemellomida99723 жыл бұрын
Hello bro, i really love watching your videos, these helped me a lot as a self-learner and beginner in java greetings from the Philippines♥♥♥
@BroCodez3 жыл бұрын
Glad you like them! Thanks for watching Rochelle!
@Stella-ic7nc4 ай бұрын
thanks for summarizing what my lecturer spent 1,5h talking about !
@fire_krystal11 ай бұрын
best explanation out there! thanks sm
@amada.103 жыл бұрын
Hahah I literally like this video, everytime you create a catch function, you don't forget to include a silly word🤪😂😂😂
@Ragehunter Жыл бұрын
tysm for the examples it was clearly understandable :)
@amadujalloh47003 жыл бұрын
Geez what is more beautiful than reading Big Java text book and watching the practicals here with my bro? Nothing is better in Java than @Bro code...
@fareskamal41452 жыл бұрын
thank u i wish every one explains in ur way
@kairavpathak21783 жыл бұрын
I subbed. Ur videos are so easy to understand. Thank god I found your channel. Otherwise I would be lost in the yt coding world
@BroCodez3 жыл бұрын
Glad to have you here Kairav!
@kairavpathak21783 жыл бұрын
Could you upload some vids in your gaming channel too? Like maybe once a week if you are busy or something.
@cosecE2 жыл бұрын
recommended your channel to all my juniors
@danny.30363 жыл бұрын
Thanks, Bro! ☕ You're awesome!
@helenaa13048 ай бұрын
Thanks Bro, I really needed this for my comp sci class 👍
@dhmilan6077 Жыл бұрын
Damn!! What a simple and easy way to teach
@hemanthneupane86083 жыл бұрын
I subscribed your channel right away I saw this series. I was having trouble learning java and i had not found any good videos on youtube. Thank you! Your videos are helping me all way out!
@BroCodez3 жыл бұрын
thanks for watching Hemanth!
@shockwave24773 жыл бұрын
Great playlist
@FarizDarari Жыл бұрын
HUGE THANKS!!!
@deltashit2 жыл бұрын
Thank you! Now I finally understand the try and catch blocks. But why is the finally block even needed? Could you not just write the code inside the finally block after the whole try-catch and it would still be executed just fine?
@AdelitoTeca-mi6xg4 ай бұрын
very nice, you´re great on it
@ShermukhammadKarimov2 ай бұрын
thanks for clear explanation
@RK_Rom302 жыл бұрын
brooo you videos is educational at somehow entertaining hahahaa
@danishhussain96423 ай бұрын
Great teaching, Bro!
@infinitepossibilities26142 жыл бұрын
2:22 - Surroud any Dangerous code with the try block. Haha that was amazing bro!
@chrisstuff8235 Жыл бұрын
Bien expliqué. Merci Monsieur
@kameshwaranr35693 ай бұрын
God level explanation bro😎
@anapopova9199 Жыл бұрын
It was interesting and good to know! Thanks 🙂 I will follow you!
@user-sn1vn2ik2oАй бұрын
awesome!
@speklex77910 ай бұрын
dope video
@yusufmarzuki312819 күн бұрын
good one !!
@alanwarthon Жыл бұрын
Perfect!, thanks.
@adarshvardan6825 Жыл бұрын
your videos are very helpful
@michael_scarn_ Жыл бұрын
Bro, hats off, thanks a million
@lm_slayer1 Жыл бұрын
I passed my exam because of you KINGGGGGGGG
@kemann38152 жыл бұрын
Another great one 👌
@azerpashahuseynli4443 жыл бұрын
Thank you Bro, perfect explanation
@user-et7bw8hn9m7 ай бұрын
bro, your my go to when my teacher fails me. Thank you.
@user-eo6sv1gs7pАй бұрын
Nice Bruhh I love Your Video
@thanhhuyvu45302 жыл бұрын
i understood try-catch. Thanks Bro
@113_03 Жыл бұрын
Thank you bro u really saved my life
@fakharjafri350511 ай бұрын
I watched this video to solve a question on hackerank, which I haven't solved in 6 months. It seems easy now, thanks bro
@user-ed7ue4fu6z Жыл бұрын
Thanks pal, that was quite helpfull
@mpbabu802 жыл бұрын
Excellent teaching
@xxg3fallxx58911 ай бұрын
very nice explanation
@airadjurad89349 ай бұрын
good explanation :)
@lucnahounou9 ай бұрын
Thanks!😁
@fitzsimmons75 ай бұрын
thank you, this was helpful
@shukragaming Жыл бұрын
THANKS YOU SAVED MY DAY
@firsttime8064Ай бұрын
love u man, thx
@salahadinshemsu6186 Жыл бұрын
Bro!! love you
@codesloth9402 жыл бұрын
Your my hero bro
@romanrubanovich92733 жыл бұрын
Thanks, Bro!
@aliaskararzykulov23612 жыл бұрын
good job bro
@alexshepel55993 жыл бұрын
Nice, bro!
@itzyuzuruclips11 ай бұрын
Pretty cool bro
@avoisavo4 ай бұрын
very usefullll
@trinithvihanga50843 ай бұрын
goood content
@azizt67738 ай бұрын
Bro you are Amazing thank you so much
@Emir-yo8ek Жыл бұрын
Ty man!
@kippenvogelchen97173 жыл бұрын
very good!
@PatrickWayne07 Жыл бұрын
Thanks Bro!
@dhrubarajroy_08653 жыл бұрын
nice
@adityasharma6132 Жыл бұрын
continue always
@user-rq6ty6ee6z6 ай бұрын
ur the best
@pouspot616 Жыл бұрын
thanks brocode for the toturial
@minhtetpaing16953 жыл бұрын
Thank you so much sir.
@danielsullivan5287 Жыл бұрын
actually watching this in class to help me on my lab