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.    1 | 2 | Next »

Posts:4
Registered: 8/5/04
Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 9:48 AM



 
Hi, im very new to java and im looking on how to solve this problem...i use eclipse if that helps any

Syntax error on token "}", "finally" expected....why is that coming up? any suggestions on how to fix it?

Heres the code:

import java.io.*;
class ReadNumber

{

public static void main (String []args)

{

BufferedReader d = new BufferedReader(new InputStreamReader(System.in));

try

{

{

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

String numberString = d.readLine();

for (int i = 0; i <= numberString; i = i + 1);

{

System.out.println(i);

}

}

}

}

}

 

Posts:349
Registered: 1/8/04
Re: Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 9:50 AM (reply 1 of 21)



 
If you "try" something, you have to "catch" something.
 

Posts:349
Registered: 1/8/04
Re: Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 9:51 AM (reply 2 of 21)



 
See here:
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
 

Posts:349
Registered: 1/8/04
Re: Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 9:52 AM (reply 3 of 21)



 
And know this:
http://forum.java.sun.com/features.jsp#Formatting
 

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



 
i had that catch but then when i tested it it said: Syntax error on keyword "catch"; "}" expected.
}
catch(IOException ioExc)
{

how do i fix that?
 

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



 
oh and thanks for the tip on posting code on this forum
 

Posts:349
Registered: 1/8/04
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 9:58 AM (reply 6 of 21)



 
how do i fix that?

This is your clue:
"}" expected.

You should type a "}" somewhere.
 

Posts:2
Registered: 8/5/04
Re: Syntax error on token "}", "finally" expected..what do i need to change?  
Aug 5, 2004 9:58 AM (reply 7 of 21)



 
If you "try" something, you have to "catch" something.

You got that right. I tried a new oriental spa and caught the clap.
 

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



 
If you "try" something, you have to "catch"
something.

You got that right. I tried a new oriental spa and
caught the clap.

Yikes. I tried a Culprit and caught a largemouth...
 

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



 
This is your clue:
"}" expected.

You should type a "}" somewhere.

i did type a "}" somewhere and it made no difference...
 

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



 
This is your clue:
"}" expected.

You should type a "}" somewhere.

i did type a "}" somewhere and it made no
difference...

"Somewhere" doesn't count in Java. You have mismatched braces, no catch clause, and are trying to compare int to String. Fix these problems and you'll be golden.

http://java.sun.com/docs/books/tutorial/
http://java.sun.com/learning/new2java/index.html
http://javaalmanac.com
http://www.jguru.com
http://www.javaranch.com
Bruce Eckel's [url=http://mindview.net/Books/DownloadSites]Thinking in Java[/url]
Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]Effective Java[/url]
Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance]Head First Java[/url]
 

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



 
Fix these problems and you'll be golden.

YaaaBing!!
 

Posts:349
Registered: 1/8/04
Re: Syntax error on token "}", "finally" expected..what do i need to change  
Aug 5, 2004 11:33 AM (reply 12 of 21)



 
You should type a "}" somewhere.

i did type a "}" somewhere and it made no
difference...

Type it somewhere else.
Then count and make sure you have as many "{" as "}".

I'm assuming that you're reading through the first link I gave you now. In it you will find examples of how to use try-catch blocks. When you have it worked out, you will have a different error in your code: the int-String problem that yawmark's eagle eyes found.

At that point, post your code again and we can discuss how to find out how to convert a String to an integer.
 

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



 
At that point, post your code again....

WAIT!

When you post code, please use [code] and [/code] tags as described in [url=http://forum.java.sun.com/features.jsp#Formatting]Formatting Help[/url] on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].
 

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



 
Like this...
import java.io.*;class ReadNumber {     public static void main (String []args)     { 	BufferedReader d = new BufferedReader(new InputStreamReader(System.in)); 	try 	    { 		{ 		    System.out.println("Enter number to count to:"); 		    String numberString = d.readLine(); 		    for (int i = 0; i <= numberString; i = i + 1);  		    { 			System.out.println(i); 		    } 		} 	    }     } }
 
This topic has 21 replies on 2 pages.    1 | 2 | Next »