 third recursion method here, the mixed one with a mix of string and integer values. I ran out of time in the last video, it was getting a bit too long. So I'll just go through this with a visual trace and then also using the debugger after that. So let's get started. So we know that when we run our code we run the main method. So we're in the main scope to start with. We've got an integer called n which is 19. Got an integer 2 which is 3. I've got a string called s which is equal to this function called here. So the function is called convert and it has two parameters called desval and base 2. So we'll be calling this function here with 19 and 3 and so this will get placed on the top of our call stack. So we're going to be inside this function scope here. This is decimal value and this is base 2. Alright so we're inside this scope here. Let's trace. So if the decimal value is equal to 0, so no because it's 19, it's a skip over that. We've got a variable called last which is equal to the decimal value modulo base 2. So 3 goes into 19 6 times with 1 remainder. So that's how value there and then I've got remaining which I'll just write rem is equal to decimal value divided by base 2. So 19 divided by 3 will get 6 point something but it doesn't matter because we're dealing with integers so we just get 6. Line 17 got string called sub which is equal to the return value of this function called again. So another recursive function with a parameter remaining being our new decimal value and our base 2 is still the same. So I've got convert and I said my decimal value was my remaining which is 6. My base 2 is the same. So to find out what sub is equal to I've got to enter this function here. So this function gets put on top of the call stack and we leave the function that we're in to find out what convert 6 3 returns before continuing on just putting some labels there to help me out. Okay so we've entered this function so we're back on line 12 decimal value 0 no. So I've got last is equal to the decimal value modulo base 2. So 6 divided by 3 you get 2 with no remainder so last is 0 and then you've got remaining try writing as rem is equal to decimal value divided by base 2 so I guess 2 here. Now I've got sub which is equal to a recursive function call with parameters decimal value is equal to remaining which is 2 and base 2 stays the same. So I've got convert 2 3 so another function call we put on top of our stack so we're leaving this function here we're entering convert 2 3. We'll keep going so is the decimal value equal to 0 no last is equal to decimal value modulo base 2 so 2 or 3 goes into 2 0 times so there's 2 remainder line 16 remaining is equal to decimal value divided by base 2 so 2 divided by 3 we're dealing with integers so that is equal to 0 and then we've got a string called sub which is equal to another recursive function call convert remaining which is 0 and then base 2 is the same. So again what does convert 0 3 return? Okay if the decimal value is equal to 0 in this case it is so this here is returning the string 0 okay so we've finally gotten to our base case where we're returning an actual string an actual value and we know that we're returning that back to the function call which is up here so convert 0 3 return 0 so in this context here sub inside this scope this scope here sub is equal to 0 place that and now that we've returned something from this function we can pop that off the stack because we're exiting that function and now we can continue on inside this scope here inside convert 2 3 so when we were here the last line we were on was 17 with these is our values so if we go to 18 it says we've got a string called result which is equal to sub plus last so 0 plus last and here last is an integer but because we've got a string so we've got the string 0 and we're plusing an integer 2 this plus is usually considered as an addition symbol so 2 plus 3 you get 5 but when there's a string involved it's considered a concatenation symbol so you're merging two values together so what's happening here is it says okay I've got a string here I've got an integer here I want to add them together so what Java does is it says okay consider the integer as its string value so instead of the int value of 2 it's converted it to a string so what this becomes is no space in there 0 2 okay so we'll move on so we get to line 19 if result character at 0 is 0 well that's true because our character at 0 0 and result dot lengths is greater than 0 that's true and return result plus substring 1 so it's a substring starting at index 1 so we're returning this is our string these are our indexes so what we're returning is just 2 because we've got a substring that's starting at index 1 which is just hit this here so this is being returned to the function call of convert to 3 which is up here so you know that this is equivalent to 2 and now that we've returned a value from here once we return a value and a function we exit that function which means it's popped off the call stack and now we're in this scope so again we'll continue on so the last line more on the 17th and then we're in 18 18 we've got result is equal to sub plus last so sub we get 2 and the same thing before with concatenating a string and an integer it's 2 plus 0 so it's 20 or 2 0 so the string we get to line 19 if result dot character at 0 is equal to 0 this is our string here and in this case the character at 0 is this one here and it's not 0 so this condition will be false which means we'll go to the else and we're just returning result so we're returning just result as it is 20 and this is being returned to our function call which is up here so convert 6 3 returns the string 2 0 now that we've returned something from this function here we exit the function and it is popped off the call stack so we're getting there so now we're back into this scope here line 17 now on line 18 we've got result is equal to sub plus last sub is 20 last is 1 and again concatenating a string and an integer so the integer turns to its string value get to line 19 our condition says if the character at 0 in result so this is 0 1 2 character at 0 this one here and that's a 2 so this is false which means this whole condition will be false and that means that we go to our else and we just return result as it is we're returning result and that is returning to our function call so now we're finished here we're back into our main context the last line that we were on in main was 7 so now we have string s is equal to the string 2 0 1 so if we print that out we should get 2 0 1 so that's the trace for that one so let's have a quick look at the debug for that so we can check our answer and I'm going to put a breakpoint here again you can put your breakpoints anywhere but I'm just going to put it on the initial function call and I am going to run and then debug great so I'm in my main I've got n is equal to 19 2 is equal to 3 get to this line here s equals convert n 2 so this should put this onto the call sack because we're inside here so I'll step into that and there we are we're here we've got decimal value is 19 base 2 is 3 is the decimal value 0 no last is equal to decimal value modulo base 2 get 1 remaining 6 and then we've got another recursive call here so this should put this onto the call stack and then we'll jump back to line 12 because we've entered a new function great okay we'll just continue on so we've got last we've got remaining recursive function call so that gets added to the stack decimal value is not zero so that won't be true continue through this one we've got recursive function call so that gets added to the stack and here if we have a look our decimal value is equal to zero so we know that this condition will be true so we'll go to line 13 and this says return zero so we're returning the string zero back to the previous one on the call stack so when I run this that should be popped off the top and we're back to line 17 so now I've got sub is equal to the string zero right go over that sub is equal to the string zero and we're on the previous one on the call stack result was equal to sub plus last oh I did it again let's step out of this one there we go sub plus last so we've got zero to this should return true so we'll go to line 20 I'm gonna step over that return result dot substring one so this should return just the string with a number two I should have stepped over again I always make that mistake all right so we've popped that one off the stacks now in the previous one and we've returned the string two so when I step into the next line sub should have the value two or the string two now we've got result is equal to sub plus last so two plus zero so we'll get the string two zero I always press the wrong button and there we go we'll step over it and now I've got this condition here is the character at zero zero for result now it's a two so we'll head to our else and we'll go to line 22 we're returning result result is two zero so that should be returned to our previous layer in the stack and the top one will be popped off return to zero step over sub is to zero that's what we expected result is equal to sub plus last so it should be two zero one that's good is the character at zero zero no it's a two so that should head well that won't be true so we'll head to our else we'll get a line 22 we're returning result and now we're returning result back to our main method and we're going to start back at line seven so step here back to line seven we've returned two zero one next step s is equal to two zero one so when we run the rest of our program we should be printing that there so that is how you do that trace there in both the debug mode and also visually