how to pass command line arguments to main method dynamically

后端 未结 4 1330
生来不讨喜
生来不讨喜 2020-11-29 10:25

I am passing my main class as a command line argument to launch VM

Now i need to pass command line arguments to that main class

Is there any way to do this?<

4条回答
  •  悲&欢浪女
    2020-11-29 10:54

    We can pass string value to main method as argument without using commandline argument concept in java through Netbean

     package MainClass;
     import java.util.Scanner;
     public class CmdLineArgDemo {
    
    static{
     Scanner readData = new Scanner(System.in);   
     System.out.println("Enter any string :");
     String str = readData.nextLine();
     String [] str1 = str.split(" ");
     // System.out.println(str1.length);
     CmdLineArgDemo.main(str1);
    }  
    
       public static void main(String [] args){
          for(int i = 0 ; i

    Output

    Enter any string : 
    Coders invent Digital World 
    Coders invent Digital World
    

提交回复
热议问题