How can I run a java Main with multiple lines as its argument using Intellij?

Viewed 415

I've written a program to read a series of lines and then reverse the order of input. The problem is now, how can I pass multiple lines into the Main method?

I have tried to run the console using the green arrow next to Main but this is what it looks like and me typing anything doesn't have any results (It should have printed the lines in reverse after 3 inputs but it didn't)
enter image description here

Another thing I've tried is to put "first line \n second line \n third line \n" inside edit run configuration after you right click the green arrow, but that still treats the entire argument as 1 line.

I want to know, how can I have it similar to C#, where you can press F5 to open up a console, and I type in "first line" then enter key then "second line" then enter key then "third line" then enter key for my program to detect that I have already entered 3 lines and reverse and terminate it for me?

1 Answers

At my IntelliJ version there is a "double arrow" besides the command line arguments for the run configuration. When I click it, I get a multiline input dialog an can edit multiple lines there.

enter image description here

So the following program

public static void main(String[] args) throws  Exception {
    for (String s : args) {
        System.out.println(s);
        System.out.println("-----------");
    }

}

outputs to

abc
-----------
def
-----------
Related