I will assist you to understand some Java. You will have to do some
writing on your own to get it to work. There are lots of similarities
to C++ but that only gets you close. I've numbered the program lines
above, skipping spaces. I'll refer to these and give you my comments.
You'll have to interpret and modify the program on your machine.
Line 1. You aren't doing anything with the io API. You don't need the
import statement. Ditto with the throws portion of the main method
declaration (3). You are not throwing anything in this module. You musta copied
that from somewhere else? Get rid of it. Get rid of lines 6 & 7, too. What were
you thinking? You declared heads and tails twice. You'll get compile errors all
day! Line 15 is a better declaration, anyway.
Line 9. Where did this brace come from? In Java, these things rarely
float by themselves. You'll see this with a static method declaration
but you aren't doing that here. Find it's closing mate and get rid of
both of them.
Line 10. First, I'd make tmp a double, simply because it will be less
messy when you start making the random method call. Don't call rand()
here. Just declare the variable. Then make a new line like 10, only
like this: tmp = Math.random(); and stick it after line 17.
The Math API is static, so you don't need to make any declarations
for it, just use it. Math.random() returns a double, which is why tmp
is a double (otherwise you get a warning message about losing
precision). random() returns a value of 0.0 up to but not including
1.0. On line 11, I recommend you change the test to: tmp < .5 so that
half of all random() returns will be less than .5 and become heads.
Then take lines 11 through 14 and place them after the line you
already placed after line 17.
Line 16 is not Java. Dump it. You are using the Math API and it
handles seeding the random numbers. Read about it in the JavaDoc
http://java.sun.com/j2se/1.4/docs/api/index.html if you need the
details.
Line 17 is missing the brace at the end of the line. This and the
missing end brace which goes before line 19, define the scope of the
for statement. Line 18 looks like an attempt to call a method that is
not defined. The lines you moved from 11-14 do the job so you can get
rid of 18. If you have to have a method, you will have to change the
scope of your variables. Right now they are all local to the main()
method. Get it working first, then do the refactoring is my
suggestion.
Line 19 is attempting to cast the result to a double. You need to
enclose double in parentheses--> (double). The abs() method lives in
the Math API as well, so code it just like the random() method.
Once you make these changes and compile a few times, you'll have it.
You'll be ready to read the java tutorial and start coding in Java,
not C++!