Kotlin - Adding Numbers
A free video tutorial from Fahd Sheraz
Lead Web Developer & Software Engineer | Instructor
4.3 instructor rating • 6 courses • 70,659 students
Learn more from the full courseKotlin Android Development Masterclass
Learn Kotlin, Android Development, Android Studio & IntelliJ IDEA from Scratch. Build Android Apps in Kotlin.
32:16:59 of on-demand video • Updated February 2020
- Build sophisticated Android Oreo Apps using Kotlin
- Quickly master Kotlin Programming language
- Become a Confident Kotlin and Android Developer who is hirable
- NEW Content and Updates will be added to the course frequently
- FULL SUPPORT - Your answers will be answered promptly!
English [Auto] This reading that I learn about operations and operator so namely We're going to learn about adding to numbers. You know let's go ahead and create a new file here calling in to say Dacian and get rid of this. Let's copy all of is and put it here and get rid of all of it. Almost all of it not all of it. Eric go. We don't need this anymore. There we go Ed.. OK. How to add two numbers so the first thing we're going to do is to create two variables and these variables are going to be var because we want to change that. So it's a VAR for us and I'm going to make it 10 var. And is going to be 20 Nexavar it's going to be resolved. Maybe we can go ahead and call this going to give it a type of. All right. All right so here all we can do we can say results it's going to be equal to first and last second home like that. So our result here will have the addition between first and second numbers. So mean you know an out of print. And and we're going to say result or we can say to be better we can say this this is a result like that we save and right click and run we should see the sum is 30. All right. That's very good. So we were able to create 2 numbers here first and second and we created a variable that is not necessary. But I did it and we just to show you. So this variable here we said result is of type and because it has to accept it. Can we make sure that say it's going to be normal. And here are you saying it can be. No that's not a big deal. And we say resolve then is going for some Plus Second all second number. And then we are displaying the some day we kind of said if we wanted actually we could have just said the following report inside here could have said it first plus second. Just like that. Now this is a different notation that I haven't shown you here. If we wanted to display an actual expression as we have here. So we took the first nonplus second and we put it all here to make it easier. You have to put inside of curly braces. OK. So you say the dollar sign and you open the braces and we can put for some Plus second down here in this case we don't need our result anymore. OK that's another way to do it. So we save this we should run and you see nothing really has changed in terms of result but we know that in our code here we've changed how we are displaying it or how we retrieving the variables Skate's my first name. Second that's perfect so we can do of course change all of these numbers here something like that if we save Brian we should have the addition of these numbers here. And the beauty also is that here we can go ahead and if we wanted to add another actual number save this and run who should have 330 because we added 120. So I'm going to go ahead and comment on those out. There's different ways to do the same thing here. It'll be able to learn how to add two numbers and you also learn a new way of concatenating or in a way to add variables. Inside a blue print line here inside of a string. So you put a dollar sign curly braces and you put in this case first number plus second number and it gives you the summation of those two numbers and you are good. So go ahead and play with this. In fact you could take this knowledge that you have here and go back to the previous program that you wrote about the story the customer conversation and he can add a little bit more of a of interactivity to that program. All right. Perfect. I'll see you next.