solution needed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

20th Nov 2022, 3:37 PM
Mustakim Rahman
Mustakim Rahman - avatar
2 Answers
+ 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>();
20th Nov 2022, 3:56 PM
Giannis
Giannis - avatar
0
Thanks ❣️
23rd Nov 2022, 6:51 AM
Mustakim Rahman
Mustakim Rahman - avatar