1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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

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

  1. rickjames8710

    rickjames8710 New Member

    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

    Did you compiled it as console App ?
     

Share This Page