Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with Stacks

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Help with Stacks

    import java.util.*;
     
    public class StackDemo{
    public static void main(String[] args) {
    Stack stack=new Stack();
    stack.push(new Integer(10));
    stack.push("a");
    S.o.p("The contents of Stack is" + stack);
    S.o.p("The size of an Stack is" + stack.size());
    S.o.p("The number poped out is" + stack.pop());
    S.o.p("The number poped out is " + stack.pop());
    }
    }
    hello,everyone....please help me with this codes....thanks....
    Last edited by helloworld922; December 16th, 2010 at 11:54 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help with Stacks

    In the future, please don't hijack someone else's topic. I've moved this for you.
    What's the problem you have? One thing I can see that's wrong is that you've abbreviated System.out.println. This is not ok in Java, you must explicitly spell out all identifiers. Another thing that I can see is that you've forgotten the generic parameters. I'm not sure why you would want to add both integers and strings to the same stack, that's generally not a good idea. However, you can use the base class Object as the generic parameter you.

    Stack<Object> stack = new Stack<Object>();

Similar Threads

  1. help for stacks
    By msa0127a in forum Algorithms & Recursion
    Replies: 0
    Last Post: October 3rd, 2010, 12:11 AM
  2. Palindrome Stacks
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2010, 03:05 AM