No Sampath Problem is in elseif it should be as else if (separate by space) :-)
So not it's working. thanks lot for your corporation. Nelson Rodrigo Staff Officer - Software Development LOADSTAR (PRIVATE) LIMITED Sri Lanka | Tel: +94 11 483 7914 | Fax: +94 11 224 0892 | Mobile: +94 77 311 6556 P SAVE PAPER - Please consider our environment before printing * _____ From: Rajeev Sampath [mailto:[email protected]] Sent: Thursday, February 26, 2009 5:46 PM To: [email protected] Subject: Re: [java ee programming] Re: Input String Values str.equals("*") --> this can be problematic. i ithink '*' is a metacharacter in java. [ just like u use it when doing a file search in windows - it represents one or more characters - matches with any character]. so when u try to find an equivalent to '*', the equals() methods understands it as 'any character', so all the time it will return true. to solve this problem, u may use str.equals("\\*") [ or may be "\\\\*", i'm not quite sure] this tells that u dont want to match it with any character, instead it tells that u want an exact match with '*'. On Thu, Feb 26, 2009 at 5:01 PM, Nelson Rodrigo - LHQ <[email protected]> wrote: Dear Sampath, Thanks its working Can you please check following code? there are small problem in else part if (str.equals("+")) { addval( no1, no2); } elseif (str.equals("-")); { subsval( no1, no2); } elseif (str.equals("*")) ;{ multval( no1, no2); } else; { System.out.println("Operator invalid. Please enter valid operator (+,*,-)"); } Nelson Rodrigo Staff Officer - Software Development LOADSTAR (PRIVATE) LIMITED Sri Lanka | Tel: +94 11 483 7914 | Fax: +94 11 224 0892 | Mobile: +94 77 311 6556 P SAVE PAPER - Please consider our environment before printing * _____ From: Rajeev Sampath [mailto:[email protected]] Sent: Thursday, February 26, 2009 4:37 PM To: [email protected] Subject: Re: [java ee programming] Re: Input String Values when you use '==' on an object, it compares only memory addresses - not the actual content (in this case, the characters contained within string need to be compared - not where it is stored.....). so don't compare string values by references. use equals() method instead. if (symbl.equals("+")) { addval( no1, no2); } else { ..................... } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en -~----------~----~----~----~------~----~------~--~---
