0

Sorry for the really bad title but I have no idea how to explain it without an example.

My problem is that I need to write a program that will do its operation on a number that is inputted when the program and class is opened.

For example a program that have a class that multiples a number by 3 would be "java program.multiply(3)" in the command line. How am i able to take the input of 3 when its wrote with the command to open the program?

And again sorry for the bad explanation I'm having a really hard time explaining it considering its quite simple

  • 1
    This should point you in the right direction - https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html. – Riaan Nel Feb 04 '20 at 19:45
  • 3
    You'll notice every java program has a `main` methods that takes one argument, an array of Strings, `args`. Anything you type after `java yourProgram` will be in this array. – sleepToken Feb 04 '20 at 19:45
  • 5
    Does this answer your question? [What is "String args\[\]"? parameter in main method Java](https://stackoverflow.com/questions/890966/what-is-string-args-parameter-in-main-method-java) – maio290 Feb 04 '20 at 19:45
  • @sleepToken But that's not the same as specifying the argument like in the post. Wouldn't that require `java program.multiply 3`, `instead of java program.multiply(3)`? – Scratte Feb 04 '20 at 20:10

0 Answers0