Это можно сделать очень просто с помощью счетчика:
public static void printFirstEvenNumber(int total) {
for (int i = 0, j = 0; j < total; i += 2, j++)
System.out.println("Even number " + i + ", count is " + j);
}
Демо
printFirstEvenNumber(4);
Even number 0, count is 0
Even number 2, count is 1
Even number 4, count is 2
Even number 6, count is 3
I'm not sure exactly what you're asking for, but does jsbin satisfy your needs?
The hard part of what it sounds like you want to do is going to be parsing the javascript so that you can do intelligent things with it. The CodeMirror library can help you develop something to put on a page.
UPDATE:
Etherpad isn't around anymore but Ace is really nice. It's got a long history and is the engine used by the Cloud9 IDE