Could someone please review my code and let me know if there is any scope for optimization for better performance.
package com.gmail.practice;
import java.util.Arrays;
public class Stacks {
private int top;
int size;
int[] stack;
public Stacks(int arraysize)
{
size = arraysize;
stack = new int[size];
top = -1;
}
public void push(int value)
{
if(top == size-1)
{
System.out.println("the value cant be pushed: Stack underflow");
}
else{
top = top+1;
stack[top] = value;
}
}
public void pop()
{
if(top > size-1)
{
System.out.println("stack is overflow");
}else{
top = top-1;
System.out.println("current top value is " + " " +stack[top]);
System.out.println("the popped value is" + " " + stack[top+1]);
}
}
public void display()
{
for(int i=0;i<size-1;i++)
System.out.println(stack[i]);
}
public static void main(String[] args)
{
Stacks s = new Stacks(5);
s.push(10);
s.push(15);
s.push(19);
s.push(3);
s.pop();
s.push(4);
s.display();
s.pop();
s.pop();
s.display();
}
}