simplifying it and even eliminating the switch statement entirely to make the code more efficient in practicehoweverit' usually more practical to rethink the algorithm from the beginningusing stack-based approach instead of recursive approach listing shows what happens when we do that with the triangle(method listing the stacktriangle java program /stacktriangle java /evaluates triangular numbersstack replaces recursion /to run this programc>java stacktriangle app import java io */for / ///////////////////////////////////////////////////////////////class stackx private int maxsize/size of stack array private int[stackarrayprivate int top/top of stack //public stackx(int /constructor maxsize sstackarray new int[maxsize]top - //public void push(int /put item on top of stack stackarray[++topp//public int pop(/take item from top of stack return stackarray[top--]//public int peek(/peek at top of stack return stackarray[top]//public boolean isempty(/true if stack is empty return (top =- )///end class stackx