The current issue I am having with this code is: figuring out why don't I see any output. I take some of your suggestion: Here is a revise version of my code:
//import java.io.*;
//import java.math.*;
//import java.io.OutputStreamWriter;
import java.io.BufferedInputStream;
//import java.lang.*;
import java.util.*;
import java.util.Scanner;
//import java.io.PrintWriter;
//import java.io.UnsupportedEncodingException;
//import java.util.Locale;
public class StdIn {
private static Scanner scanner = new Scanner(new BufferedInputStream(System.in));
public static boolean isEmpty()
{ return !scanner.hasNext();}
public static String readString()
{ return scanner.next();}
public static void main (String args[]){
Stack<String> ops = new Stack<String>();
Stack<Double> vals = new Stack<Double>();
while (!StdIn.isEmpty())
{ // Read token, push if operator.
String s = StdIn.readString();
if (s.equals("(")) ;
else if (s.equals("+")) ops.push(s);
else if (s.equals("-")) ops.push(s);
else if (s.equals("*")) ops.push(s);
else if (s.equals("/")) ops.push(s);
else if (s.equals("sqrt")) ops.push(s);
else if (s.equals(")"))
{ // Pop, evaluate, and push result if token is ")".
String op = ops.pop();
double v = vals.pop();
if (op.equals("+")) v = vals.pop() + v;
else if (op.equals("-")) v = vals.pop() - v;
else if (op.equals("*")) v = vals.pop() * v;
else if (op.equals("/")) v = vals.pop() / v;
else if (op.equals("sqrt")) v = Math.sqrt(v);
vals.push(v);
System.out.println(vals.push(v));
} // Token not operator or paren: push double value.
else vals.push(Double.parseDouble(s));
System.out.println(Double.parseDouble(s));
}
System.out.println(vals.pop());
}
}