File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes NEED HELP!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NEED HELP!!!" Watch "NEED HELP!!!" New topic


Noah Faust

Joined: Mar 07, 2009
Posts: 26
This is my original code

This is what my compiler is saying

C:\Documents and Settings\Noah\My Documents\javastuff>javac cannot find symbol
symbol : variable y
location: class Guessthenumber
} while (y != rand1);
1 error

How can I fix this?

public class Signature {
public static void main (String[] args) { System.print.ln (//insert witty phrase here) }
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

'y' is declared inside the 'do' block, but the value check is outside that block and cannot see the variable.

Try this:

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Welcome to the Ranch! We're glad you dropped in. We have written a guide to help you get the most out of your time here, which I advise you to look over.

Specifically, I'd recommend you start with these two.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Noah Faust

Joined: Mar 07, 2009
Posts: 26
I managed to fix it by changing my loop to this:

if (y == rand1) {

} while (true);

Thanks for the help! and sorry about the tag line...
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82

Just a suggestion regarding the style of your solution. The solution may work, but could be difficult for others to read. Take a look at section 3 of the Ranch Style Guide for some helpful suggestions.
I agree. Here's the link:
subject: NEED HELP!!!
jQuery in Action, 3rd edition