Home arrow static arrow Java Programming [Archive] - Syntax error on token "}", "finally" expected..what do i need to change?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Syntax error on token "}", "finally" expected..what do i need to change?
This topic has 21 replies on 2 pages.    « Previous | 1 | 2 |

Posts:2,206
Registered: 8/15/02
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 11:53 AM (reply 15 of 21)



 
Which remonds me of a language feature I encountered earlier. I am sure the JLS allows it, but I still find it odd that the following will compile outside a try/catch block
public class Test {    public static void main(String[] args)    {        for ( int i=0; i<Integer.parseInt(args[0]); i++ ) {            System.out.println(i);        }    }                                                                                                       }
 

Posts:24,036
Registered: 2/3/03
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 11:54 AM (reply 16 of 21)



 
Which remonds me of a language feature I encountered
earlier. I am sure the JLS allows it, but I still
find it odd that the following will compile outside a
try/catch block...

Why odd? It's an unchecked exception.

<curious />
 

Posts:24,036
Registered: 2/3/03
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 11:55 AM (reply 17 of 21)



 
NumberFormatException, that is...
 

Posts:2,206
Registered: 8/15/02
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 11:57 AM (reply 18 of 21)



 
You're right, my bad. Thought it was a checked exception
 

Posts:96
Registered: 3/25/99
Re: Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 2:14 PM (reply 19 of 21)



 
If you "try" something, you have to "catch" something.
Well, not exactly. You can have a try/finally block, too.
fitz
 

Posts:183
Registered: 5/28/04
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 6, 2004 4:54 AM (reply 20 of 21)



 
i use eclipse if that helps any
Yeah, it can here a bit. Highlight a brace, and then pick Navigate - Go To - Matching bracket.
 

Posts:342
Registered: 5/22/98
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 6, 2004 7:01 AM (reply 21 of 21)



 
Here are some things I spotted while looking at your code,

try

{

{

Why 2 opening braces?


System.out.println("Enter number to count to:");

String numberString = d.readLine();
for (int i = 0; i <= numberString; i = i + 1);

A few things to note here:.

1 The first problem will give you this error :

The operator <= is undefined for the argument type(s) int, String


But, you could probably pick this up (and the solution) from previous posts.

2. This one has happened to the best of us at one time or another and will cause this error:

i cannot be resolved


This is because you inadvertently added a semicolon to the end of your for statement.

3. Just an observation; take a look at the ++ and += operators, you'll grow to love them.



{

System.out.println(i);
Note the previuosly mentioned error

}

}
<== Hmm, I wonder what goes in here?

Graeme

 
This topic has 21 replies on 2 pages.    « Previous | 1 | 2 |