This discussion is archived
5 Replies Latest reply: May 19, 2013 1:19 AM by EJP RSS

Java compile error

AhmedMahzin Newbie
Currently Being Moderated
class stack
{
private int maxSize;
private int top;
private long[] stackArray;

public stack(int size)
     {
maxSize = size;
stackArray = new long[maxSize];
top = -1;
     }
//---------------------------------------------
public void push(long i)
     {
if(top == maxSize-1)
System.out.println("Can't insert, stack is full");

else
stackArray[++top] = i;
     }
//---------------------------------------------------------

public long pop()
{
if(top == -1)
System.out.println("Can't pop, stack is empty");

else
return stackArray[top--];

}

public boolean isEmpty() {
return(top == -1);
}


public long peek() {
return stackArray[top];
}

}

class stackApp {
public static void main(String args[]) {

stack stack1 = new stack(5);

stack1.push(10);
stack1.push(20);
stack1.push(30);
stack1.push(40);
stack1.push(50);
stack1.push(60);

stack1.pop();
stack1.pop();
stack1.pop();
stack1.pop();
stack1.pop();
stack1.pop();


System.out.print("Top value is "+stack1.peek());

}

}


when compiled i get
stack.java:32 error: missing return statement
}
1 error

please help....!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points