Another Pseudocode Example – Intro to Java Programming


The pseudocode should print 10, then 5, 16, 8, 4, 2. We start out with n is 10. And then, check if n is still greater than 1, print n, which is 10. Then, if n is even, which it is, because it’s 10. We update n to be half of n, and then we skip the stuff in the else. We come back here, n is still greater than 1. This time, it’s 5, so we print n 5. And then if n is even, which it isn’t, we would have done that. So we go to the else, and we update n to be 3 times 5 plus 1. So 15, 16. We come back up to the while and check again. And it’s still greater than 1. 16, so we print 16, n is even. So we update n to be n over 2, so it’s 8 now, skip the else. Check again. 8 is greater than 1, so we print 8. n is even, 8 is even, so n is 8 over 2, is 4. Skip the else, come back up. 4 is greater than 1, so we print 4. If n is even, it is. So, n becomes 4 over 2, so it’s 2. Skip the else. 2 is greater than 1, so we print n. Print 2. n is even so we update it. n becomes 2 over 2, so it’s 1. Skip the else. Now, n is no longer greater than 1. So we drop out of the bottom, and we’re done. If this still looks a little foreign, that’s okay. We’re going to do more practice with pseudo code later.

Leave a Reply

Your email address will not be published. Required fields are marked *