Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Brackets { } .........

 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been typing in examples from a chapter on Methods, and I thought I understood what was going on.
Until now.
My problem concerns the use of brackets { } when writing code.
Below is what I thought the solution to a factorial problem - this is my solution. Well, when I say 'my' solution, I mean the book code, but with as much of it as possible anticipated by me and written, only looking at the book when stuck.

There is a syntax error in it, and for the life of me, I can't figure out where it is.
Below is the book solution, which compiles and runs fine.

I think there error in my solution lies in the use of the { } brackets.
Can anybody see what I've done wrong, and why?
I have spent HOURS breaking my thumbs trying to figure it out, but to no avail.
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,
Here's a revised version of your code -

Notice that I finished off with the main method & then went on to write the next method f i.e you need one "}" before static long f(.. & you gotta remove one "}" from the end.
HTH
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh!!

I see now.
I failed to notice that the main method, must be enclosed by { } just like any other method should be.
Cheers for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic