public class MyStack {
String str;
StringBuilder expression;
static final String operationalCharacters = "+-*/()";//操作符号
static final String number = "012345689";//数字集
public MyStack(String str) {
this.str = str;
generateExp();
}
public void generateExp(){
expression = new StringBuilder();
for(char ch:str.toCharArray()){
if(isNumber(ch) || isOperationalCharacter(ch)){
expression.append(ch);
}
}
}
public String getExp(){
return expression.toString();
}
public boolean isNumber(char ch){
return number.indexOf(ch) >= 0;
}
public boolean isOperationalCharacter(char ch){
return operationalCharacters.indexOf(ch) >= 0;
}
public void showItems(){
System.out.println(expression);
}
public static void main(String[] args) {
MyStack s = new MyStack("d5 ~c+ 2$+a32*10b");
s.showItems();
}
}