In both examples he is using the trick that the digits sum to 9 in any number that is a multiple of 9 (by "digits sum to 9" I mean if you keep going til there's only one digit left). The rest is just window dressing to hide the simplicity of the trick.
So in the first example you will see "multiply by 3, multiply by 3, sum to one digit". It doesn't matter what you did before this point - he now knows your answer is 9. Then he got you and the other student to add/subtract different numbers (to hide the fact you both had 9). All he had to do was work out 9+1 and 9-4.
In the second example you will see "multiply by 3, multiply by 6, divide by 2, sum to one digit". 3x6/2 = 9 so again you are multiplying by 9 and summing to one digit. Again, he now knows you have 9 and just needs to do 9x2+2=20 in the subsequent instructions to know your number is 20.
Notice that as soon as he's got you to sum the digits, he doesn't get you to add/subtract/multiply/divide "by any number" any more? That's because that's the point at which he knows your number. Any calculations before that point are meaningless, so you might as well do "any number", whereas if you did "any number" after the critical "multiply by 9 and sum to one digit" bit he would lose the information he has on your number.
Why this works
Basically this works because 9, 99, 999 etc are all multiples of 9 which means that:
1000 ≡ 100 ≡ 10 ≡ 1 mod 9
Since you are a high school student I am not sure if you've come across modulo notation so I will try and explain in layman's terms (Christoph gives a nice formal answer for those that are looking for one).
1000 ≡ 100 ≡ 10 ≡ 1 mod 9
means that for all those numbers (and, indeed, any power of 10, not just the ones I've listed), when you divide by 9 you get a remainder of 1. So if you divide 10n by 9 you get a remainder of n (e.g. 50/9 gives remainder 5) - a remainder of one for each 10 that you had (since 10-9=1).
Clearly, in order for the whole number to be divisible by 9, you need a total remainder that is divisible by 9. So 54 works because the 50 gives a remainder of 5 and the 4 gives a remainder of 4, and 5+4=9.
This is really a special case of the way it works with any number. So, with 8, you have a remainder of 2 for every 10 and a remainder of 4 for every 100. So if you multiplied the 100s digit by 4, the 10s digit by 2 and the 1s digit by 1 you would get a multiple of 8 (and 8 itself if you kept going to one digit). 8 divides 1000 so you wouldn't need to do any other calculations even if you had bigger numbers. 9 is just special because the remainder is 1 in each case, so you can simply "sum to one digit" without multiplying different digits by different things.
If you wanted to impress your teacher you could read his mind without multiplying by 9 by making the adjustments for multiplying by another number (say, 8) as above :)