Your Java solution should have a single command-line argument representing the number of candidates.
I am having trouble understanding the homework question.
Your Java solution should have a single command-line argument representing the number of candidates.
I am having trouble understanding the homework question.
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.
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
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
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>
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.