Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Zahir Sercan
Greenhorn
+ Follow
1
Posts
1
Threads
0
Cows
since Jan 19, 2012
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (1/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (1/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Zahir Sercan
Switch error: incompatible type found
Hi Java buddies,
Im building a expression tree calculator. Im now stuck with a problem here is the code snippet.
Method Postfix
public String Postfix() { String res = " "; if (this.left != null) { res += this.left.Postfix() + " "; res += this.right.Postfix() + " "; } res += this.Value; return res; }
Methode Solve
public int Solve() { String a, b; String[] tokens = Postfix().split(" "); for (String e : tokens) { //byte, char, short of int switch(e) { //At this point i get an error: incompatible types; found : java.lang.String; required: int case "+": b = stack.pop(); a = stack.pop(); stack.push(Integer.toString(Integer.parseInt(a) + Integer.parseInt(b))); break; case "-": b = stack.pop(); a = stack.pop(); stack.push(Integer.toString(Integer.parseInt(a) - Integer.parseInt(b))); break; case "/": b = stack.pop(); a = stack.pop(); stack.push(Integer.toString(Integer.parseInt(a) / Integer.parseInt(b))); break; case "*": b = stack.pop(); a = stack.pop(); stack.push(Integer.toString(Integer.parseInt(a) * Integer.parseInt(b))); break; case "%": b = stack.pop(); a = stack.pop(); stack.push(Integer.toString(Integer.parseInt(a) % Integer.parseInt(b))); break; default: stack.push(e); System.out.println(stack.pop()); break; } } return Integer.parseInt(stack.pop()); //return 1; }
Any idea or advice what i can do to solve this problem?
Cheers
show more
12 years ago
Java in General