I admit it's a part of an assignment but I don't understand what the assignment require in this part.
This program is supposed to read 10 numbers from the keyboard and then the application findMax will take one single command line argument.

If you invoke findMax 1, it will print to the screen the largest number amongst the ten numbers.

If you invoke findMax 2, it will print to the screen the second largest number amongst the ten numbers.

If you invoke findMax 3, it will print to the screen the third largest number amongst the ten numbers.

What does invokeing mean?! does the user input 1, 2 or 3 after inputing the 10 numbers ?!
Any help is appreciated...

Recommended Answers

All 12 Replies

invoking means calling.
first you read ten numbers from the keybord (either command line parameters, or using input, Scanner, or another reading method), and then you enter one number from one to ten.
if input = 1
runMethod1
else if input = 2
runMethod2
...

Do you know how to start (invoke) a java program by entering a command line on a command prompt window?
For example: java TheClass thearg

"thearg" is passed in the String[] args array passed to the main() method.

That's very helpful, thanks stultuske & NormR1.

That's what I was looking for, invoking by entering a command line. How can I randomize "thearg" for example, to be between 1 and 3 (can it be different every time I run the program?) and if it didn't invoke, how to set a default output?

Thanks a lot.

How can I randomize "thearg"

The command line is entered by you and can contain whatever you can type on a keyboard.

how to set a default output?

Do you mean a default input?
In the program you can test the (String[] args) argument and if the array is empty you could assign it a default value.

Why does this invoking

"java FindMax 2;"

says (can't find symbol
symbol: class java
location: class FindMax)?!

Please copy and paste here the full contents of the command prompt window where you entered that command line. You don't use a ; on the command line. Just press Enter after typing the line.

On windows: To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

I don't use a command prompt window but an Netbeans IDK. Does it make a difference here?

Sorry, I don't know how to use that IDE. All my posts were about using a command prompt window.
I have no idea if you can create a commandline in an IDE.

findMax, if I read your code well, shouldn't be a class, but should be a method.
and this is indeed much easier (especially if you have to use command line parameters) by the command prompt. the IDE will automatically just run "java YourClass" without any parameters.

NormR1: Thanks for your time. :)
stultuske: yes findMax is a method. :)
But I need to pass a parameter which will decide on the output of the program. If I passed 1 ---> largest number of the 10 .... so on. That's the requirement of the assignment.

The parameter is passed directly to your main method from whatever command prompt or IDE has started your program. This link shows how to pass and use such a parameter in netbeans.
ps This is yet another good example of why most of us advise beginners to stay with an editor and command prompt at first. An IDE just adds another layer of complexity and learning curve.

That's very helpful, thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.