Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: pls tell me where the problem is....

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pls tell me where the problem is....

    i m quite new to java programming...pls tell me the mistake in the following programme...

    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();
     
    }
    Last edited by helloworld922; November 16th, 2009 at 03:05 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default 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.