‫Now that you're correct in creating methods that don't have a return value, we will have a look at
‫return values and there will be an integer, for example.
‫So let's go ahead and create a method.
‫Public static void and void is the incorrect term here because we don't want to use empty return values,
‫we want to use a return value of type integer, for example.
‫And I'm going to call that method edX and I'm going to hand over to parameters.
‫So para meter one and parameter two.
‫Now that by itself won't work because those parameters need to have a type as well.
‫So they need to know of which data type they are.
‫And in this case, I'm going to use two integers and I want to return the result of parameter one plus
‫parameter two, and I'm going to call them num one because it's just going to be a number and number
‫two.
‫So just for easier reading and easier understanding of what's going on.
‫So they are parameters, yes, but are numbers.
‫And that makes it easier to understand that this method is going to add number one and number two.
‫All right.
‫So it's going to return an integer.
‫And now we still get an error here.
‫And it says program, dot add program is our class.
‫That is the method.
‫Not all code paths return a value.
‫What that means is that we need to have a return statement in every single path that we have.
‫And so far we only have one path and we will get to know other paths later on.
‫So if we, for example, have, if else statements where if one condition is true, then we want to
‫return X, and if another condition is true, then we want to return Y, for example.
‫So in this case we only want to return one thing, and that is going to be number one plus num two.
‫So this method should simply add the two values.
‫And if I call that method add and in here, let's say I add an argument of 15 and 31, then this program
‫here will simply add those two numbers together and give us the sum.
‫So if you run that, nothing happens or the command prompt opens real quick or a console and then it
‫exits because there's nothing else to do.
‫It did calculation and then, well, we didn't hold it.
‫We didn't say, come on, we want to see something.
‫So if we want to see something, there are two ways.
‫Either I create a variable which is going to be the result and I'm going to store the result of our
‫add return inside of this variable.
‫Now, the next step would be to simply print that onto our console.
‫So I'm going to write a line result and I'm going to read the whole thing.
‫So if I run that, I'll see the result of 46 and that's great.
‫But there is another way I can make it even simpler.
‫So I don't need this whole line here.
‫I could simply say here, add 15 plus 31 and I can get rid of this whole line of code because what that
‫will do is it will simply write the result of or the return value of the call of this method.
‫So you can use a method as an argument because to be honest, we have used arguments all the time.
‫Whenever we use the right line method, we use arguments because whatever we have written in here,
‫my text, that's an argument.
‫It's an argument of type string.
‫And now if I say ADD, now this is an argument as well.
‫It's an argument which is the return of my ADD method, which is of type integer.
‫So this one here simply represents 46.
‫And what I can do as well, I can call my ADD method and I can call my add method within my ADD method
‫so I could add one plus two and then add three and four, and that would be still totally fine.
‫So this looks a little confusing, but no worries.
‫That's usually not something that you would do.
‫I just wanted to show you that a method that returns something is equal with, when you call it, is
‫equal to the return value itself.
‫So in this case it would be three plus and then that would be seven.
‫So that result would be ten.
‫So if I add that console, that right line and I run the code, that's what I get.
‫So I get ten and 46.
‫All righty.
‫So I hope that didn't confuse you.
‫But what is important is that you can have return types and you can have multiple different parameters.
‫All right.
‫Now, please go ahead and create a method that multiplies two values to each other and returns the result
‫of that multiplication.
‫All right.
‫I hope you tried it.
‫So now let's go ahead and create another method, and it should return an integer as well.
‫Multiply and that will be int num one and int num two.
‫And it has to return something.
‫And in this case, it will return num one multiplied with num two.
‫And this is designed for multiplication.
‫So you simply use the star to multiply.
‫All right, now let's call that method instead.
‫So multiply, let's say 25 times 25.
‫So that should be 625.
‫And there we are, 625.
‫So you see, you can use that for adding for multiplying, for division as well.
‫So let's create a divide method static and now I'm going to use double because it can be a floating
‫point result and I don't want to cut it off.
‫I want to be as precise as possible when I do division.
‫So I'm going to use double here and I'm going to call that divide and it's going to divide two values
‫from each other or one through the other, and return none one divided by num two.
‫And this one needs a type as well.
‫So in this case, I'm using two integers.
‫Let's see what happens, because I return a double.
‫But as parameters, I still use strings.
‫So let's divide 25 by 13.
‫And we get one.
‫Why do we get one?
‫That's so weird.
‫5025 divided by 13 is not one.
‫It's actually almost two.
‫But the problem lies in those integers here.
‫So we are dividing an integer through an integer and the result will be an integer.
‫And then what we do is return it as a double.
‫So this one here is 25 divided by 13, which is 1.9, and then you just cut off the nine.
‫So it's 1.0, and that is what is double returns.
‫So it simply returns one.
‫So if we instead use doubles here, so we divide divide a double through a double, then we get this
‫1.9 or 1.9, two, three and so forth.
‫So you have to be very careful with your types.
‫So whenever you use division, check out what the result is that you want to you want to cut off anything
‫behind the floating point and using integers totally fine but otherwise use bubble great.
‫So this will just some examples.
‫You can of course not only use integers here, you can use strings, you can return strings, you can
‫return not only our basic data types, you can also return whole objects, complete objects.
‫And that is something that we will cover much later when we handle objects.
‫I'd say that's a good start for methods.
‫Please go ahead and try to create some methods of your own and that will be a challenge that will give
‫you some instructions.
‫Great.
‫So see you in the next video.