Hi i'm making a program to see if parenthesis are balanced, only one kind ( & ) , ok let's say you type in (()), it will be balaced. This will be easier to explain if i attach some of the code: ( I PUT THE SPOT IN THE CODE IN CAPS WHERE I NEED HELP) thanks
public class test3{
public static int top;
public static String[] s;
public static void main(String args[]){
String s1;
String s2 = "(";
s = new String[5];
top = 0;
s1 = JOptionPane.showInputDialog("Enter Expression"
for(int j=0; j <= s1.length(); j++)
{
if(s1.charAt(j) == '(')
{
BASICALLY RIGHT HERE I WANT TO SEND '(' TO THE METHOD
PUSH WITH OUT RETURNING ANYTHING, HOW DO I DO THAT??
}
if(s1.charAt(j) == ')')
{
// GO to pop method
}
}
}
public void push(String ob)
{ if ( top == s.length )
{ // array is full---create a new one to hold more objects:
String[] temp = new String[s.length * 2];
for ( int i = 0; i != top; i = i+1 )
{ temp = s; } // copy elements into temp
s = temp; // set s to hold address of temp
}
s[top] = ob;
top = top + 1;
}
Thanks []v[]attyD
public class test3{
public static int top;
public static String[] s;
public static void main(String args[]){
String s1;
String s2 = "(";
s = new String[5];
top = 0;
s1 = JOptionPane.showInputDialog("Enter Expression"
for(int j=0; j <= s1.length(); j++)
{
if(s1.charAt(j) == '(')
{
BASICALLY RIGHT HERE I WANT TO SEND '(' TO THE METHOD
PUSH WITH OUT RETURNING ANYTHING, HOW DO I DO THAT??
}
if(s1.charAt(j) == ')')
{
// GO to pop method
}
}
}
public void push(String ob)
{ if ( top == s.length )
{ // array is full---create a new one to hold more objects:
String[] temp = new String[s.length * 2];
for ( int i = 0; i != top; i = i+1 )
{ temp = s; } // copy elements into temp
s = temp; // set s to hold address of temp
}
s[top] = ob;
top = top + 1;
}
Thanks []v[]attyD