• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in a simple loop program  RSS feed

 
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.
 
Marshal
Posts: 58454
178
  • 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
Marshal
Posts: 58454
178
  • 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.
  •  
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!