0
Hello, I’m doing a project with stack and queue, and I’m in a part I need to pick up the operator and put in a pile and the number in a queue.
However this part of taking the number is not working, someone has a light to work, because what I used the net is not working. Note: not giving error!
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
String exp;
Fila fila = new Fila();
Pilha pilha = new Pilha();
int valor;
try {
System.out.println("Digite um texto.");
exp = input.next();
StringTokenizer st = new StringTokenizer(exp, "+-*/^()", true);
while (st.hasMoreTokens()) {
if (campoNumerico(st.nextToken())) {
try {
valor = Integer.parseInt(st.toString());
fila.insere(st);
} catch (NumberFormatException e) {
System.out.println("Numero com formato errado!");
}
} else {
pilha.empilhar(st.nextToken());
}
// String delimitador;
// Float.parseFloat(st.nextToken());
}
fila.mostrar();
} catch(Exception erro) {
}
System.out.println("Valores pilha: " + pilha);
}
private static boolean campoNumerico(String campo){
return campo.matches("[0-9]+");
}
}