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 3 of 3

Thread: someone can help me ?

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default someone can help me ?

    hey , hope u guys doing well . i just want to ask for some help . its not about solving my coding but about understanding in java . my teacher had give me an exercise and ask me to type it using jcreator . i figured it out and the process complete . but the problem is i dont fully understand about the question that i had been gave . can anyone help me explain the coding that i've attach here with adding some comment in the coding ?

    so this the first coding .

    import java.util.*; 
    class StackDemo {
    static void showpush(Stack st, int a) {
    st.push(new Integer(a));
    System.out.println("push(" + a + ")");
    System.out.println("Stack: " + st);
    }
    static void showpop(Stack st) {
    System.out.print("pop -> ");
    Integer a = (Integer) st.pop();
    System.out.println(a);
    System.out.println("stack: " + st);
    }
    public static void main(String args[]) {
    Stack st = new Stack();
    System.out.println("stack: " + st);
    showpush(st, 42);
    showpush(st, 66);
    showpush(st, 99);
    showpop(st);
    showpop(st);
    showpop(st);
    try {
    showpop(st);
    } catch (EmptyStackException e) {
    System.out.println("empty stack");
    }
    }
    }

    and this is the second conding .

    import java.util.*;
     
    public class StackDemo1{
    	public static void main(String[] args) {
    		Stack stack=new Stack();
    		stack.push(new Integer(10));
    		stack.push("a");
    		System.out.println("The contents of Stack is " + stack);
    		System.out.println("The size of an Stack is " + stack.size());
    		System.out.println("The number poped out is " + stack.pop());
    		System.out.println("The number poped out is " + stack.pop());
     
    		System.out.println("The contents of stack is " + stack);
    		System.out.println("The size of an stack is " + stack.size());
    	}
    }
    Last edited by skyzred; July 19th, 2011 at 11:37 AM.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: someone can help me ?

    Quote Originally Posted by skyzred View Post
    but the problem is i dont fully understand about the question that i had been gave .
    You might want to check out the link in my signature on asking smart questions, especially the bit about writing clearly. Many of our users do not speak English as a first language, and so it can be hard to understand incorrectly written posts.

    That being said, what question? What's your question? What happened when you stepped through this with a debugger?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,775
    Thanks
    54
    Thanked 2,340 Times in 2,311 Posts

    Default Re: someone can help me ?

    What does the program print out when it executes?
    The code is very straight forward. There are no loops or conditional statements. It starts in the main() method and goes sequentially thru the statements. Each statement does something.

    Please copy and paste here each statement that you don't understand what it is doing and post a question about your problem understanding.
    Before doing that be sure to read the API doc for that statement as that will be the first thing we'll ask you to do if your question doesn't show that you have read the API doc.