• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in a simple loop program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
  •  
    Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic