-
prefix evaluation method
the program runs but i still have problem for example i enter +56 and return 11 but when i tried to enter -+567 return 25 instead of 23 also when i tried to enter +45-3 it return 9 so after 5 the program stop it just return the addition of 4+5
public static int prefixEvaluation(String s){
int result=0 ;
int i=1;
char ch = s.charAt(0);
s=s.substring(i , s.length()); // i want to be able go though the entire string
if (ch>='0'&& ch<='9'){
result=((int)ch-48);
System.out.println(result);
return result;
}
else if (ch=='+'|| ch=='-'|| ch=='*'|| ch=='/'){
char op=ch;
System.out.println(ch);
int operand1= prefixEvaluation(s);
s = s.substring(i++);
int operand2= prefixEvaluation(s);
-
any suggestion of how to to read the string everything i call the recursive function
Similar Threads
-
Replies: 2
Last Post: 08-05-2006, 10:40 PM
-
Replies: 1
Last Post: 04-21-2006, 11:51 AM
-
Replies: 1
Last Post: 04-13-2006, 04:57 AM
-
Replies: 0
Last Post: 09-01-2005, 01:12 AM
-
Replies: 3
Last Post: 04-13-2001, 09:13 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks