aspose file tools*
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
Author

NEED HELP!!!

Noah Faust
Greenhorn

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 Guessthenumber.java
Guessthenumber.java:21: 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
Rancher

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
Bartender

Joined: Oct 02, 2003
Posts: 11322
    
  16

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.

Thanks!


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

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


if (y == rand1) {
break;
}

} while (true);

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

Joined: May 16, 2008
Posts: 82
    
    2
Noah,

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.
Larry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NEED HELP!!!