Please help me on this delimeter check program please...
java program that checks the pairing of (); []; {} ... i mean, for example, the equations inputed is a = {x[3*2(1+9)]+99}.. we know that there is no error in that eq... then the result would be *empty* which means there is no error.... but if you input a = {x[3*2(1+9]) + 99} , then there is an error... .the output would be ERROR.... because ] AND ) are swapped... please help me o.O
Re: Please help me on this delimeter check program please...
Do you honestly think that you constructed a valid question, which is clear and understandable?
Re-word everything, ask a direct question, specify your problems along with any exception messages and post some code which you've started writing (must be relevant!).
But note, this is not a homework service and no one is going to hand you the code on a silver platter.
Oh, and in the members intro section? really?
Re: Please help me on this delimeter check program please...
Thread moved. KathCasison, please read the forum rules, and I would highly recommend reading the getting help link in my signature.
Re: Please help me on this delimeter check program please...
Sorry.... I would like to ask some help for my homework. I requires a program that checks delimeters.. I've started the codes but it doesn't work properly.. here it is:
import java.util.*;
public class thom{
public static void main (String args[]){
Stack st=new Stack();
Scanner thom=new Scanner(System.in);
LinkedList<Character>list;
list=new LinkedList<Character>();
String state=" ";
System.out.print("Input statement: ");
state=thom.nextLine();
int b=0;
for(int a=0;a<state.length();a++){
if ((state.charAt(a) == '/')&&(state.charAt(a+1) == '*')){
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
st.push(new Character(state.charAt(a+1)));
list.add(new Character(state.charAt(a+1)));
}
if ((state.charAt(a) == '*')&&(state.charAt(a+1) == '/')){
b=list.getLast();
if (b=='*'){
st.pop();st.pop();}
else
st.push(new Character(state.charAt(a+1)));
list.add(new Character(state.charAt(a+1)));
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == '['){
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == ']'){
b=list.getLast();
if (b=='['){
st.pop();}
else
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == '('){
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == ')'){
b=list.getLast();
if (b=='('){
st.pop();
}
else
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == '{'){
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
if (state.charAt(a) == '}'){
b=list.getLast();
if (b=='{'){
st.pop();
}
else
st.push(new Character(state.charAt(a)));
list.add(new Character(state.charAt(a)));
}
}
try{
System.out.println(" "+st);
}catch(EmptyStackException e){
System.out.println("empty stack");
}
if(st.isEmpty()){
System.out.print(" No error");
}
else
System.out.print(" error");
}
}
Re: Please help me on this delimeter check program please...
Please edit your post and remove the coloring. It is almost unreadable.
Also wrap your code in code tags: http://www.javaprogrammingforums.com...do=bbcode#code