You are confusing JAVA and JavaSCRIPT.
*LOOK* at the error message you are getting:
Code:
story.java:1: class, interface, or enum expected
var it = 0;
^
That is a JAVA error.
You can't use the keyword
var in Java. You can't use
document.write in Java.
MAKE UP YOUR MIND: Are you trying to write a Java program or a JavaScript program???
If it's JavaScript, then you can *NOT* try to send the code through a JAVA compiler.