Fetch the repository succeeded.
package week6;
import java.util.Scanner;
/**
* Demonstrates the use of an expression tree to evaluate postfix expressions.
*
* @author Lewis and Chase
* @version 4.0
*/
public class PostfixTester
{
/**
* Reads and evaluates multiple postfix expressions.
*/
public static void main(String[] args)
{
String expression, again;
int result;
Scanner in = new Scanner(System.in);
do
{
PostfixEvaluator evaluator = new PostfixEvaluator();
System.out.println("Enter a valid post-fix expression one token " +
"at a time with a space between each token (e.g. 5 4 + 3 2 1 - + *)");
System.out.println("Each token must be an integer or an operator (+,-,*,/)");
expression = in.nextLine();
result = evaluator.evaluate(expression);
System.out.println();
System.out.println("That expression equals " + result);
System.out.println("The Expression Tree for that expression is: ");
System.out.println(evaluator.getTree());
System.out.print("Evaluate another expression [Y/N]? ");
again = in.nextLine();
System.out.println();
}
while (again.equalsIgnoreCase("y"));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。