• March 10th, 2012, 08:26 AM
KathCasison
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
• March 10th, 2012, 08:42 AM
newbie
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?
• March 10th, 2012, 10:00 AM
copeg
• March 10th, 2012, 10:20 AM
KathCasison
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);

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)));
st.push(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)));
st.push(new Character(state.charAt(a)));
}

if (state.charAt(a) == '['){
st.push(new Character(state.charAt(a)));
}

if (state.charAt(a) == ']'){

b=list.getLast();
if (b=='['){
st.pop();}

else
st.push(new Character(state.charAt(a)));

}

if (state.charAt(a) == '('){
st.push(new Character(state.charAt(a)));
}

if (state.charAt(a) == ')'){

b=list.getLast();
if (b=='('){
st.pop();
}
else
st.push(new Character(state.charAt(a)));
}

if (state.charAt(a) == '{'){
st.push(new Character(state.charAt(a)));
}

if (state.charAt(a) == '}'){

b=list.getLast();
if (b=='{'){
st.pop();
}
else
st.push(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");

}
}
• March 10th, 2012, 10:43 AM
Norm