‫Great.
‫No, you know how to create methods and you have proven that in the challenge.
‫So let's go ahead and see how we can use user input to run methods as well or to use our methods as
‫well.
‫And therefore we are going to have a look at how to get user input in general.
‫So I'm going to use a string and I'm going to call it input and this is going to be console dot and
‫we don't write something, we want to read something and that will be read line.
‫By that.
‫We prompt the user to read, to write something so that we can use it later on.
‫So that will be stored in a string called input.
‫And what we then can do is simply write that onto the console so we know what we have written and that
‫might not make that much sense yet, but this is just to see how it works in general.
‫All right.
‫So this is a very simple input program and we can put something into our command console.
‫So there it is.
‫It doesn't say that we should write something.
‫It's just waiting for us to type something.
‫So I'm going to type hello and it says hello and then I'm going to type.
‫Is somebody there?
‫And it shuts down so it's not done for endless loops or endless entries.
‫That's something that we are going to see later on when we use while loops.
‫But for now that's good.
‫So you know how to use one user input per line of code.
‫So this line of code takes the user input the second time we use it, it simply closes the program because
‫there's nothing else to do.
‫So it uses the user input, then it writes it and then it reads it onto the console and afterwards nothing
‫is happening.
‫So there is no code to execute.
‫So our program simply shuts down.
‫So now let's have a look at a adding tool.
‫So a little calculator which just does adding nothing else.
‫And yeah, for you as a little challenge, you could try to do that yourself.
‫So please go ahead and try to use that functionality that you see here to create a simple tool that
‫adds one plus one or whatever the user enters.
‫So the user input plus the user input and the user should be informed about what is to do.
‫So I know this is quite a challenging one, but please try to do that yourself.
‫All right.
‫I hope you tried it.
‫I hope you created a little method, and I'm going to create.
‫Well, you could have done it in the main method in general, but I'm going to create a little method
‫just because we are inside the methods chapter and I'm going to call it public static int and calculate.
‫This one is going to be an integer num one.
‫Actually, this is not going to be an integer.
‫It's going to simply return
‫a result.
‫And of course we need to create that result.
‫So I'm just going to create that result for now, just so we have it there and it's going to be five.
‫Now in here, what we want to have is the two entries of the user and we want to store them.
‫So first of all, we need to use right line so the user knows what he has to do.
‫Please enter the first number and then the user can enter the first number.
‫So this is going to be a string number one input and we use console dot read line.
‫So we read what the user types and then we do the same thing.
‫So we need to have the second number as well.
‫So console right line, please enter the second number and again we need to store it within a string
‫number two input which is console dot red line.
‫So now we have the two numbers.
‫What we now need to do is add them together.
‫But thing is they are strings.
‫So we cannot add them.
‫We cannot add strings to each other.
‫Well, we do or we can, but that's concatenation.
‫It's not really math here.
‫What we want to do is to get the mathematical result, and what we need here for is to convert them
‫into integers.
‫So I'm going to convert number one input.
‫Into a new variable which are called int num one, which is going to be int thought parse.
‫And what is it that we want to parse?
‫We want to parse number one input.
‫Now the same thing with the second number num two and parse and number two input.
‫So we want to make numbers out of what the user has entered and then we want to calculate the result
‫and actually we have the result variable here already.
‫That should be num one plus num two.
‫All right.
‫So now what is left to do is to actually write the result onto the console so we can do that right here
‫console or actually let's use this return because otherwise we wouldn't need the integer, so let's
‫use the result to write it here.
‫So what we do is we call our calculate method right here, and it's going to give us the return of this
‫method.
‫So whatever the user enters, we're going to calculate the result or the sum of them.
‫That's it.
‫So we won't need this input here anymore, but we will need the rest.
‫So now that we have that, let's check it out.
‫Let's see if it's working.
‫So please enter the first number.
‫I'm going to enter 25.
‫Please enter the second number, I'm going to enter 99 and I see the result of 124.
‫So now we have to be super careful because we do parsing here and we haven't seen decision making it.
‫So we don't know how to see if it worked or it didn't work.
‫Otherwise we could have used try pass or we could have used try and catch.
‫But that's something that we will handle later on.
‫For now, it's just important that you only enter numbers when you test that because as soon as you
‫don't.
‫So let's see.
‫Please enter the first number.
‫I'm going to use P and enter the second number I'm going to use I and our system crashes because it
‫says it can't pause and P or an AI into a number or into an integer input string was not in a correct
‫format.
‫All right.
‫But that's something as I said, we will handle that later on.
‫What's important now is that you see how you can read values from the user.
‫So that's something that we're going to use more and more throughout the course because user input is
‫much more interesting than just having it in here, just having some code in here which does things,
‫but it doesn't feel the same as you might understand.
‫Great.
‫So I hope you tried it.
‫I know it wasn't easy and this is not the only way to call this calculate method.
‫You could have also used the void instead here and not return a result, but instead simply write the
‫line here and give out the result.
‫So result like that and simply call the calculate method here.
‫By the way, let's stop that calc you light like that.
‫So that would have been the other solution.
‫Just to use a void method here, do the right line here and then just call the method there.
‫All right.
‫Those are multiple options.
‫Great.
‫So I'd say I'm going to save it here and see you in the next video.