VSC에서 main 함수 매개변수를 지정해서 프로그램 실행 하는 방법 (How to Pass multiple arguments to my java program in visual studio code)

Denia·2022년 1월 13일
0

launch.json 파일에서 수정 (we have to Edit launch.json File)

수정 전 코드 (The code before modification)

        {
            "version": "0.2.0",
    	    "configurations": [
            {
            "type": "java",
            "name": "Launch JavaExampleProgram",
            "request": "launch",
            "mainClass": "My.JavaExampleProgram",
            "projectName": "Example_JAVA",
            }
            ]
        },

수정 후 코드 (The code after modification)

        {
            "version": "0.2.0",
    	    "configurations": [
            {
            "type": "java",
            "name": "Launch JavaExampleProgram",
            "request": "launch",
            "mainClass": "My.JavaExampleProgram",
            "projectName": "Example_JAVA",
            "args": ["bla","15"]
            }
            ]
        },

Main 함수로 매개변수를 전달하고 싶으면 launch.json 파일에서 "args"를 추가하면 된다.
(If you want to pass the parameter to the Main function, you can add "args" in the launch.json file.)

추가한 내용을 살펴보면 (Let's look at what we added.)
"args": ["bla","15"] 에서 "bla" 가 args[0] 으로 들어가고 "15" 가 args[1]로 들어간다.
(In "args": ["bla","15"], "bla" go to args[0] and "15" go to args[1].)

3개의 인자가 필요하면 "args": ["bla","15","3rd"] 로 수정해서 사용하면 된다.
(If you need three arguments, Edit "args" Like this "args": ["bla","15","3rd"] )

profile
HW -> FW -> Web

0개의 댓글