zsocc zsocc - 7 months ago 11
Java Question

Java command line set argument with "="

I have a method:

public String sample (String A, int B, int C){
String fin = "";
if(C==0){
fin="fail";
}
return fin;
}


I want to run it in command line like this:
d:>java -jar prac.jar B=5

How can I set parameter in command line with "="?

Answer

In your main method, you deal with parameters that are passed:

public static void main(String[] args) {
    // args[0] = parameter 1;
    // args[1] = parameter 2;
    // args[n] = parameter n+1;
    sample(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2])); 
}