Code example for Stack

Methods: poppushgetsize

0
    public Sqrt() { 
    } 
 
    @Override 
    public void execute(String[] currentLineElements) {
        if(stack.size()==0){
            System.out.println("Stack is empty.Please add elements to stack.");
            return; 
        } 
        if( (double) stack.get(stack.size()-1) <= 0){
            System.out.println("Cant attempt SQRT command to number <= 0");
            return; 
        } 
        double sqrtResult = (double) stack.pop();
 
 
        sqrtResult = Math.sqrt(sqrtResult);
        stack.push(sqrtResult);
        System.out.println(sqrtResult + " was added to stack!");
        System.out.println("SQRT command successfully accepted");
 
    } 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE