开发者

Semantic doubt over a problem statement?

You should have a single command-line argument representing number of objects you must generate for the user.

Just wanted to make sure that I g开发者_C百科ot this one right.

Does this mean we should pass the params to the main method?


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>


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


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.


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜