tuturyokgaming tuturyokgaming - 3 months ago 13
Java Question

Java command line parameters

I'm just wondering how to do Java command-line with parameters? For example :


javac Test.java


then


java Test 3 5


then after running the command line

expected output:


3 5


public class Test{

public static void main(String[] args){

int num1 = 1;
int num2 = 2;

System.out.println(num1,num2);


}
}

Answer

I think you can use args as input parameters.

public static void main(String[] args){
    System.out.println(args[0] + " " + args[1]);
}