Hello everyone,

How do I use command line arguments from main(String[] args) as user input in java?

My problem is that I need to make a program for an assignment. It needs to execute in 2 ways.
If no arguments are entered,
Ie. java myprogram
it opens a menu that allows the user to select an option and asks the user to input the parameters for that option.

If arguments are entered,
Ie. java my program A 5 H
It uses 'A' as the option, and '5' and 'H' as the required parameters.

I understand that:
args[0] = A
args[1] = 5
args[2] = H

I'm just unsure how to pass this information to my other methods in addition to having the option for user input via the menu.
Essentially, I can get it to do one or the other, not both. I'm pretty new to java and this is my first assignment. Everything else is working fine, I just can't get this going. I'll post code if need be but since this is a university assignment, I don't really want to get caught "cheating" considering students and teachers probably use/read this forum.

Thanks in advance!

how to pass this information to my other methods in addition to having the option for user input via the menu.

Use if/else logic. In pseudo code:
If there are args, load the values for the method calls from those args
else If there are no args, ask the user for the values to use
When you get here, the values have been set, either from the args or from the user.

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.