2 Star 0 Fork 0

CS-IMIS-23/GK20172301_JavaProgramming

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
PostfixTester.java 1.31 KB
Copy Edit Raw Blame History
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"));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/GK20172301_JavaProgramming.git
git@gitee.com:CS-IMIS-23/GK20172301_JavaProgramming.git
CS-IMIS-23
GK20172301_JavaProgramming
GK20172301_JavaProgramming
master

Search