/** * Matt Kretchmar * February 28, 2006 * Calc.java * This program implements a simple command-line calculator. * It supports A op B where A,B are floating point operands * and "op" is +, -, *, /, ^. */ class Calc { public static void main ( String [] args ) { double operand1 = 0; double operand2 = 0; double result = 0; // parse the input Strings for numeric values operand1 = Double.parseDouble(args[0]); operand2 = Double.parseDouble(args[2]); if ( args[1].equals("+") ) result = operand1 + operand2; else if ( args[1].equals("-") ) result = operand1 + operand2; else if ( args[1].equals("*") ) result = operand1 * operand2; else if ( args[1].equals("/") ) result = operand1 / operand2; else if ( args[1].equals("^") ) result = Math.pow(operand1,operand2); System.out.println(result); } }