Stacks - pop, push, peek methods

I am trying to make a program that essentially takes a string of parenthesis and outputs whether or not its balanced.

Basically, every '(' will push the index of that location of the string on to the stack, while a ')' will pop it off if it's not empty. At the end, it will peek at the stack giving me the index of the first offending parenthesis. My problem now is the code below isn't working correctly... can anyone assist me in helping me figure out what i am doing wrong?? The negative one output means it is balanced correctly.
Thank you

Ok 1 suggestion before I try to look into the problem with your code. See to it that members of your class TestData are private and not public. Write getter() and setter() method to retrieve and set them. Instead of directly using them as someParens.testInput , using the getter method to retrieve them is a much better idea. What you have done is not an error, but it is usually avoided.

well its the instructors code and i dont have to worry about that. I just need to make my code work correctly which is the first class i posted. It keeps returning -1. I can't figure out how to return the index of the string being looked at when its being pushed. if that makes any sense

When indexOf() does not find the character in the string it returns -1. When you say input.indexOf(i) it means you are trying to find first occurrence of i in the string input. Since this is always false in your case, it always returns -1. Hence -1 is pushed always.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...