1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why don't I see any output from my program?

Discussion in 'Java' started by rickjames8710, Jan 15, 2012.

  1. rickjames8710

    rickjames8710 New Member

    Joined:
    Jan 15, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I tried compiling this program several times but did't see any output. Could anyone give me any suggestion on why I'm not seeing any output when I run this code.
    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());	
    
    
    }
    
    
    }
     
    Last edited by a moderator: Jan 16, 2012
  2. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Did you compiled it as console App ?
     

Share This Page