![]() |
| ||
| Else If statement Hello everyone, I just need help on this code. I can't debug it, I'm just new in Java and this is just my fifth assignment so I'm really having a hard time. Here's my code: import java.io.*; the Error says that: illegal start of type line 20 <identifier> expected line 20 else if (age>=18);Can anyone please tell me how to debug it? =/ |
| ||
| Re: Else If statement Your braces and semicolons are out of place. Look through your if () else if () block and check them. |
| ||
| Re: Else If statement uhmmm.. I'm sorry, but I already tried to move the braces at the "else if" line. Still I can't let it run. =( |
| ||
| Re: Else If statement Look at the structure of your class and main() method and compare that with your other assignments which do run. Also, look at the brace structure of any if-else block. The problems should be reasily apparent to you. This is about as basic as debugging can get and you need to spot the problems on your own to learn. I've already told you what the nature of the problem is, so all you have to do is look at those blocks. |
| ||
| Re: Else If statement ok.. thx.. I'll check them.. =) |
| ||
| Re: Else If statement arg.. a new error occured. >.< this is my only notes/guide for the if else statement. =( import java.io.*;The error says: - unreported exception java.io.IOException; must be caught or declared to be thrown line 12 name=input.readLine();- unreported exception java.io.IOException; must be caught or declared to be thrown line 14 age=Integer.parseInt(input.readLine());It seems like my teacher forgot something or I copied the code wrong. =( |
| ||
| Re: Else If statement I do not know what your teacher gave it to you and if you already covered Exceptions, but that what you get when you use BufferedReader getLine(). Check this tutorial and you should be able to figure it out what to do with it. Main difference between yours code and code in the tutorials is that you read from command line and tutorial do it from a file |
| ||
| Re: Else If statement Using Scanner to read the input would be easier and you wouldn't have to mess with the ioexception. http://java.sun.com/javase/6/docs/ap...l/Scanner.html |
| ||
| Re: Else If statement or just add throws IOException underneath your main method declaration. ... public static void main(String args[]) throws IOException { String name; ... that should work. |
| ||
| Re: Else If statement Quote:
The catch block should be placed within main() and handle the exception gracefully. |
| All times are GMT -4. The time now is 8:46 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC