Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in a simple loop program

 
Jayanth Raju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic