JAVA不可达到_java-开关中的不可达语句

我在代码中添加了缺少的类/接口/枚举声明,并且无法重现该错误.问题显然出在您尚未发布的代码中.

这是适合我的编译方法:

import java.util.*;

import java.io.*;

public class Test

{

public static interface Token

{

}

public static class Operator implements Token

{

public Operator(opType type)

{

}

}

public static enum opType

{

LPAR, RPAR, MULT, DIV, MOD, ADD, SUB

}

public static class Operand implements Token

{

public Operand(int val)

{

}

}

public static void main(String[] args) throws FileNotFoundException

{

ArrayList tokens = new ArrayList();

String[] readTokens;

Stack postStack = new Stack();

String filename = "input.infix";

String DELIM = " ";

File in = new File(filename);

Scanner sc = new Scanner(in);

while (sc.hasNextLine())

{

readTokens = sc.nextLine().split(DELIM);

for (String s : readTokens)

{

switch (s)

{

case "(":

tokens.add(new Operator(opType.LPAR));

break;

case ")":

tokens.add(new Operator(opType.RPAR));

break;

case "*":

tokens.add(new Operator(opType.MULT));

break;

case "/":

tokens.add(new Operator(opType.DIV));

break;

case "%":

tokens.add(new Operator(opType.MOD));

break;

case "+":

tokens.add(new Operator(opType.ADD));

break;

case "-":

tokens.add(new Operator(opType.SUB));

break;

// Assuming the expression are valid (according to the

// assignment notes, anything other than operators are

// operands.

//

// NOTE: Even though spaces exist, they will not be

// interpreted as they are the delim

default:

tokens.add(new Operand(Integer.parseInt(s)));

break;

}

}

String postfix = infix2postfix(tokens);

int finalResult = evalPostfix(postfix);

System.out.println(postfix + " = " + finalResult);

}

}

public static String infix2postfix(ArrayList al)

{

return "";

}

public static int evalPostfix(String post)

{

return 0;

}

}


版权声明:本文为weixin_35411439原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。