Search code examples
javaeclipsenetbeanspalindrome

Eclipse not running Java Code


Am really new to Java, started to study it on my own.... I downloaded netbeans and Eclipse and the two gave me the same result.. they don't run the code (stuck on running) neither let me debug it - Eclipse debugger and Netbeans - was not responding :? I don't whats wrong.. and I got no clue as I can't debug..

Here's my code: am tryin to check for palindrome:

package ClassQueue;

class Stack {

    private Object[] Stack_Array = null;
    public int top = 0;

    public Stack(int size) {
        top = 0;
        Stack_Array = new Object[size];
    }

    public Stack() {
        this(100);
    }

    protected void finalizer() {
        Stack_Array = null;
    }

    final public boolean empty() {
        return top == 0;
    }

    final public boolean full() {
        return top == Stack_Array.length;
    }

    public void push(Object token) {
        if (!full()) {
            Stack_Array[top] = token;
            top++;
        }
    }

    public Object pop() {
        Object Value_return = -999;
        if (!empty()) {
            Value_return = Stack_Array[top];
            top--;
        }
        return Value_return;
    }
}//end of Class_Stack

class Queue {

    private Object[] Queue_Array = null;
    private int Front = 0;
    private int Rear = 0;

    public Queue(int size) {
        Front = Rear = 0;
        Queue_Array = new Object[size];
    }

    public Queue() {
        this(100);
    }

    protected void finalizer() {
        Front = Rear = 0;
        Queue_Array = null;
    }

    final public boolean empty() {
        return Front == Rear;
    }

    final public boolean full() {
        return Rear == Queue_Array.length;
    }

    public void queueAdd(Object token) {
        if (!full()) {
            Queue_Array[Rear] = token;
            Rear++;
        }
    }

    public Object queueDelete() {
        Object Value_return = -999;
        if (!empty()) {
            Value_return = Queue_Array[Front];
            Front++;
            return Value_return;
        }
        return Value_return;
    }
}//end of Class_Queue

public class ClassQueue {

    public static void main(String[] args) {

        int i = 0;
        String Value_1 = "ABBA";


        Stack Value_1_Stack = new Stack(Value_1.length());
        Queue Value_1_Queue = new Queue(Value_1.length());


        while (i < Value_1.length()) {
            Value_1_Stack.push(Value_1.charAt(i));
            Value_1_Queue.queueAdd(Value_1.charAt(i));
        }

        i = 0;

        while (Value_1_Stack.pop() == Value_1_Queue.queueDelete()) {
            i++;
        }

        if (i == Value_1.length()) {
            System.out.println("Palindrome");
        } else {
            System.out.println("NOT");
        }


    }//end of main
}//end of ClassQueue

Solution

  • You've got an infinite loop here as i is never incremented:

    while (i < Value_1.length()) {
       Value_1_Stack.push(Value_1.charAt(i));
       Value_1_Queue.queueAdd(Value_1.charAt(i));
    }
    

    Also don't exceed the length of the String Value_1:

    while (i < Value_1.length() - 1) {
       Value_1_Stack.push(Value_1.charAt(i));
       Value_1_Queue.queueAdd(Value_1.charAt(i));
       i++;
    }
    

    Aside: Use Java naming conventions for variable names.