pls tell me where the problem is....
i m quite new to java programming...pls tell me the mistake in the following programme...
Code :
class CharStack{
/*Declaration of member variables*/
char[]stackArray;
int topOfStack;
/*constructor*/
public void charstack(int capacity){
stackArray=new char[capacity];
topOfStack=-1;
}
/*member methods*/
public void push(char element){
stackArray[++topOfStack]=element;
}
public char pop(){
return(stackArray[topOfStack--]);
}
public boolean isEmpty(){
return topOfStack<0;
}
public char peek(){
return stackArray[topOfStack];
}
public boolean isFull(){
return topOfStack==stackArray.length-1;
}
}
public class Client{
CharStack stack=new CharStack(50);
int i;
int length=str.length();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string:");
String str=br.readLine();
System.out.println("Original string:"+str);
for(int i=0;i<length;i++){
stack.push(str.charAt(i));
}
System.out.pritnln("Reversed string:");
while(!stack.isEmpty()){
System.out.print(stack.pop());
}
System.out.println();
}
Re: pls tell me where the problem is....
Based upon the information you provided and assuming this is all you have: First, you have no main method for the program to enter. Second, the code in Client should be contained within a method of that class. Third, your code checks the length of a variable that hasn't been declared yet (int length = str.length()) - this line should be placed after you've gotten the String str from the readLine. Fourth, you use classes from the java.io package and there are no import statements.