Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 the exit phrase
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Chinmay




PostPosted: Mon Jan 07, 2008 6:37 pm   Post subject: the exit phrase

Embarassed

Ok I have a if block inside a try block as such:

code:


try {

     if ("Hey".equals("hey") {
          System.out.print("The above two are equal, which they are not!");
     } else {
          exit;
     }

}




why would this gimme an syntax error and not exit the if and after ending the try block?
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: Mon Jan 07, 2008 6:45 pm   Post subject: RE:the exit phrase

simple, its because thats not how you use try. look at the exception tut for detail about try & catch.
int your case, you do not need try at all, so your code will simply be
code:
     if ("Hey".equals("hey")
          System.out.print("The above two are equal, which they are not!");
     else
          System.out.println("they are not equal, because i am right");


if you MUST use exit, the syntax is System.exit(int status), unless you import static System class, you cannot just say exit, and static import is only supported in java1.6 i believe Rolling Eyes
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: