views:

266

answers:

5

Your Java solution should have a single command-line argument representing the number of candidates.

I am having trouble understanding the homework question.

+3  A: 

means your program should accept a single argument (parameter), most likely an int when invoked from the command line. I am not a java guy but i am guessing something like

java -jar myprog.jar 8

I say with kindness that if that escapes you, you need to brew a pot of coffee and open the book to chapter one.

Good luck.

Sky Sanders
I think you mean: java -jar myprog.jar 8
mlaverd
thanks. will fix. maybe i will look like i am a java guy now...
Sky Sanders
+4  A: 

A command-line argument is something passed to the executable on the command line at runtime:

someprog foo bar baz.txt

So, it would take only one of these:

someprog foo

Since this is Java, you would pass it after the class name:

java myclass 3
Ignacio Vazquez-Abrams
+1  A: 

When you run your application via the command prompt, you give it a number.

For example, if your application is called "ExerciseOne", and you want it to process 10 candidates, you must run it by typing

ExerciseOne 10
Andrew Shepherd
+8  A: 

Your Java program needs to be invoked from the command prompt, say for example, MyProgram.java is a source file which contains the main() method, you compile this using the javac compiler by doing javac MyProgram.java at the command prompt to get the MyProgram.class file. This .class file is then invoked by doing java MyProgram at the command prompt to run your program.

What you need to do here is pass parameters to the main() method when you run your program simply by doing java MyProgram <your params go here>

Zaki
In your code, those command line arguments are in the `String[]` passed to `main()` which is usually called `args`.
MatrixFrog
thanks for explaining clearly. I am pretty comfortable with java, but somehow, despite having written many programs, I never came across this type of basic problem.
Karthik Kottapalli
A: 

Your main method has one argument: an array of Strings. args[0] will contain the first argument of your command line. You don't have figure out by yourself what number it represents, the Integer class has a method called parseInt that can do that for you.

Gilgamesh