- What is wrong with the following code? This piece of codeincorrectly attempts to remove all even values from a stackintegers. How would you fix it? You will need to write a class withthe main(String[] args) {….} method to test the following piece ofcode, find the problem, and fix it.
while(!s1.isEmpty()){
intn =s1.pop();
if(n % 2 !=0) {
s1.push(n);// if odd put it back.
}
}
Expert Answer
Answer to What is wrong with the following code? This piece of code incorrectly attempts to remove all even values from a stack i…