Code Scrambler
Some of the most engaging learning I’ve ever experienced was in high school Spanish class. What magic did Mrs. Lee possess that made instruction so enjoyable? She had us play countless games. I try to emulate her foreign language classroom when I teach folks a new programming language and am therefore always on the hunt for games and puzzles that my students can play.
Recently, I’ve been doing a lot of reading about scrambling up programs and asking students to reorder the lines, and I thought I’d create a little blog widget to support that style of question. The lines in the following program are scrambled. Reorder them by dragging them around!
public class Greeter {
public static void main(String[] args) {
System.out.println("Goodbye, Pluto!");
}
}
Currently there’s no feedback for getting the order correct. “Nice job!” is more heartfelt when it comes from a fellow human being. Plus sometimes several different orderings are legal.
Here’s another, longer one to print out a countdown:
import java.util.Scanner;
public class CountDown {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Starting from? ");
int max = in.nextInt();
for (int i = max; i >= 0; ++i) {
System.out.println(i);
}
}
}