Java Lesson 05: Different parameter types

From Erlands Wiki

Jump to: navigation, search

The helper class now looks as follows:

public class ArgumentHelper {
    public static int getArgumentAsInt(int argumentNumber, String[] args) {
        return Integer.valueOf(args[argumentNumber]);
    }
    public static String getArgumentAsString(int argumentNumber, String[] args) {
        return args[argumentNumber];
    }
}

And the main class looks as follows:

public class MyClass {
    public static void main(String[] args) {
    }
 
    public static void printStuffAsInt(int data) {
        System.out.println("You specified: "+data);
    }
    public static void printStuffAsString(String data) {
        System.out.println("You specified: "+data);
    }
}

The program is executed with:

java MyClass 5 Hello

Your work is to update the main method so it uses the ArgumentHelper class and the different printStuff methods to get an output like this:

You specified: Hello
You specified: 5
Personal tools