Results 1 to 5 of 5
Thread: Why does this give me an error?
- 02-03-2011, 11:03 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Why does this give me an error?
if(choice1.equals ("0"))
MainMenu();
else if(choice1.equals("Hello"))
System.out.println("Conversation initiated.");
Conversation();
else
System.out.println("Sorry? Reverting to main menu.");
MainMenu();
I don't understand where my error is. If I delete the word Conversation(); , the error goes away, but then I don't have a way to initiate my Conversation function. Any help?
- 02-03-2011, 11:06 PM #2
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
You can either have a single statement or a block within an "if".
Single statement:
Java Code:if (true) statement;
Block:
Java Code:if (true) { statement1; statement2; statement3; }
- 02-03-2011, 11:10 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Thanks, that helped me out. I managed to leave out the curly brackets.
- 02-03-2011, 11:13 PM #4
Always use braces around if statements and loops even if you do not need them. Just to avoid problems like this.
- 02-03-2011, 11:51 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Can YOU give me a project to do?
By AcousticBruce in forum New To JavaReplies: 8Last Post: 03-26-2011, 05:12 AM -
when i build my project it give following error
By enggvijaysingh@gmail.com in forum Advanced JavaReplies: 0Last Post: 11-18-2010, 11:02 AM -
I need some one to give me a hand
By HosHos in forum Advanced JavaReplies: 9Last Post: 09-05-2009, 03:18 PM -
how to give delay?
By shaluchandran in forum New To JavaReplies: 10Last Post: 12-17-2008, 05:57 PM -
Please give me a solution
By ivvgangadhar in forum AWT / SwingReplies: 5Last Post: 11-14-2008, 01:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks