Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java problem stack  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that you want the reverse method to return a reversed Stack. If so, then you're actually done after the first while loop, and all you need to do is return the new Stack at that point (instead of void).

As far as making this work in main, you just create a test Stack to work with, then create a new instance of your class (since the reverse method is non-static), then pass your test Stack to the method.
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To just make it run:

But your 'MyStack' isn't using any membervariable, so its method can be made static and called without instance:
To just make it run:
 
john mor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc Weber, Stefan Wagner!
Thank you very much.
John
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!