0

I am writing a java program that will be run from the command line and where the user should be able to indicate their preferences like this, for example:

The user wants to send from the Client to the Server their name (n) and weight (k), and they'll set the Server to have a window (w)of 4 and a delay (d) of 50%...so the commandline would look something like this:

(java abc.Client -n Roger -k 400 receiver_ip_addr receiver_port java abc.Server -w 4 -d 0.5 receiver_ip_addr receiver_port)

Everything I look up on UI from the commandline mentions reading with Scanner, like: "what is your name?" followed by: name = Scanner.nextLine();

Thanks in advance for any help!

Ang
  • 25
  • 5
  • you don't need Scanner for this, just type it as you did and get the information from the String[] args of the main method – Stultuske Oct 24 '17 at 07:41

1 Answers1

0

Check the description of the java main method: https://docs.oracle.com/javase/tutorial/getStarted/application/index.html

The main method accepts a single argument: an array of elements of type String. public static void main(String[] args) This array is the mechanism through which the runtime system passes information >to your application. For example:

java MyApp arg1 arg2

So you just need to iterate through the arguments and read them.

Veselin Davidov
  • 7,031
  • 1
  • 15
  • 23