Java Lesson 04: Multiple arguments

From Erlands Wiki

Jump to: navigation, search

The helper class looks as follows:

public class ArgumentHelper {
    public static int getArgument(String[] args) {
        return Integer.valueOf(args[0]);
    }
}

The main class looks as follows:

public class MyClass {
    public static void main(String[] args) {
        int argument = ArgumentHelper.getArgument(0,args);
        printStuff(argument);
        argument = ArgumentHelper.getArgument(1,args);
        printStuff(argument);
    }
 
    public static void printStuff(int data) {
        System.out.println("You specified: "+data);
    }
}

The program is executed as:

java MyClass 2 3

Your work is to update the ArgumentHelper class so the program compiles and gives an output like this:

You specified: 2
You specified: 3
Personal tools