Java Lesson 21: Basic stack excercise

From Erlands Wiki

Jump to: navigation, search

You have the following main class

import java.util.Stack;
 
public class MyClass {
    public static void main(String[] args) {
        Stack stack = new Stack();
        for(int i=0;i<args.length;i++) {
            stack.push(args[i]);
        }
        printLast(stack);
    }
}

Your work is to create the printLast method so it prints the last parameter, when the program is executed with:

java MyClass 5 blue Hello

It should give an output like:

The last parameter is: Hello
Personal tools