wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Guess game compiling error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Guess game compiling error" Watch "Guess game compiling error" New topic
Author

Guess game compiling error

Omar Perez
Ranch Hand

Joined: Jul 08, 2011
Posts: 36
Hello folks, I'm reading the Java head first book and I getting a issue compiling a part of my code, this is the error I'm getting.

C:\Users\Omar\Desktop>javac GuessGame.java
GuessGame.java:19: ';' expected
int targetNumber = (int)Math.random() *10);
^
GuessGame.java:23: ')' expected
System.out.println("number to guess is" + targetNumber(); //prints
^
2 errors


this the whole GuessGame class code

Justin van Wilgen
Greenhorn

Joined: Jul 06, 2011
Posts: 3
Hi, you are missing a bracket on line 19, change it as follows:
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10926
    
  12

What are you using to edit your files? Most code editors will do paren/bracket matching. If you look at your line 19:



There is an closing paren right before the semi-colon that doesn't have a matching open-paren. I'm not sure if you need the close-paren at all, but you do need to always have them in pairs.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
fred rosenberger wrote:What are you using to edit your files? Most code editors will do paren/bracket matching. If you look at your line 19:



There is an closing paren right before the semi-colon that doesn't have a matching open-paren. I'm not sure if you need the close-paren at all, but you do need to always have them in pairs.


Head First Java say to use notepad/Notepad++ because so the person can get use to catching those mistakes.

I use notepad++ Because it is almost like a ide only thing it don't have is Declares the errors and what you should use.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36590
    
  16
Notepad++ is a very good program, but it is far short of an IDE.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Justin van Wilgen wrote:Hi, you are missing a bracket on line 19, change it as follows:

Better make that (int)(Math.random() * 10). Your code first converts the result of Math.random() to an int. Since Math.random() always returns a double >= 0 and < 1, the cast will always result in 0. The total will therefore also be 0.
By multiplying first, then casting, you're casting something that's >= 0 and < 10 to an int. That can be any int from 0 to 9.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Guess game compiling error
 
Similar Threads
Very new to java
GuessGame Errors From Head First Java
Please Help with Guessing Game (Head First Java)
GuessGame errors
Head First Java Book, Chapter 2