+ 1
solution needed
Stack mystack1 = new Stack(); Stack mystack2 = new Stack(); for(int i=0; i<10; i++)mystack1.push(i); for(int i=0; i<20; i++)mystack2.push(i); System.out.println("stack in mystack1 "); for(int i=0; i<10; i++) System.out.println(mystack1.pop()); System.out.println("stack in mystack2 "); for(int i=0; i<20; i++) System.out.println(mystack2.pop()); https://code.sololearn.com/c77zL7L9Y6CO/?ref=app
2 Respostas
+ 1
There are 2 mistakes:
1) need import a library to use Stack
import java.util.*;
2) when you make a Stack you need to wonder 'stack of what?'. So you need specify you are going to fill the stack with integers
Stack<Integer> mystack1 = new Stack<Integer>();
Stack<Integer> mystack2 = new Stack<Integer>();
0
Thanks ❣️