This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem in a simple loop program 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 "Problem in a simple loop program" Watch "Problem in a simple loop program" New topic
Author

Problem in a simple loop program

Jayanth Raju
Greenhorn

Joined: Mar 12, 2013
Posts: 2
Hey,
I'm trying to make this program which finds the multiples of 7 under 400. Here it is:


And while trying to compile I get this error:
Compile error
Main.java:10: error: cannot find symbol
int y=9*x;
^
symbol: variable x
location: class Main
1 error

Anyone can tell me what i've done wrong?
Thanks!

Jayanth Raju
Greenhorn

Joined: Mar 12, 2013
Posts: 2
Jayanth Raju wrote:Hey,
I'm trying to make this program which finds the multiples of 7 under 400. Here it is:

class Main
{
public static void main (String[] args) throws java.lang.Exception
{

for(int x=1;x<=400;x++);
int y=9*x;
System.out.println(y);
}

}
And while trying to compile I get this error:
Compile error
Main.java:10: error: cannot find symbol
int y=9*x;
^
symbol: variable x
location: class Main
1 error

Anyone can tell me what i've done wrong?
Thanks!


EDIt: I found the problem, please close the thread.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36590
    
  16
Jayanth Raju wrote: . . .
EDIt: I found the problem, please close the thread.
And what was the problem? You think you can see it, but it is actually that you haven’t formatted your code properly. If you had used braces, it would have been obvious to you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36590
    
  16
You should always use code tags; since you are new I have added them and you can see how much better the code looks
I do not believe your program will fulfil its requirements.
  • 1: I think you should stop when you get to 399 = 7 × 57, not 7 × 399
  • 2: You are using 9 not 7.
  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Problem in a simple loop program
     
    Similar Threads
    Problem with protected variable...
    case???
    Operators
    Question on warnings/error
    final variables