This question already has an answer here:
- Java Command line arguments 9 answers
How to accept two digit number as command line argument and print the sum of its digits. If two digit number is 88 output will be 16. Here my task is to dont use conditional or looping statements.
Just use the first string passed from the command line adding the casted integers of each digit.
Your java class should have a
main
method as suchWhen you compile and run your class, all command line parameters will be contained in the
args
method parameter. You can read that array to get your data and do what you want with it.The main method in a java class takes String array as an argument and you can access your command line arguments using array index, for example