简体   繁体   English

如何使用 Intellij 以多行作为参数运行 java Main?

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

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?现在的问题是,如何将多行传递给 Main 方法?

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)我尝试使用 Main 旁边的绿色箭头运行控制台,但这就是它的样子,我输入任何内容都没有任何结果(它应该在 3 次输入后反向打印行,但它没有)
在此处输入图像描述

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.我尝试过的另一件事是在右键单击绿色箭头后将“第一行\n 第二行\n 第三行\n”放入编辑运行配置中,但这仍然将整个参数视为 1 行。

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?我想知道,我怎样才能拥有它类似于 C#,您可以按 F5 打开控制台,然后输入“第一行”然后输入密钥然后“第二行”然后输入密钥然后“第三行”然后为我的程序输入密钥以检测我已经输入了 3 行并为我反转并终止它?

At my IntelliJ version there is a "double arrow" besides the command line arguments for the run configuration.在我的 IntelliJ 版本中,除了用于运行配置的命令行 arguments 之外,还有一个“双箭头”。 When I click it, I get a multiline input dialog an can edit multiple lines there.当我点击它时,我得到一个多行输入对话框,可以在那里编辑多行。

在此处输入图像描述

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
-----------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 IntelliJ 在我的 java 应用程序中运行多个消费者 - How can I run multiple Consumers in my java application using IntelliJ 使用 Intellij 在 Java 中运行多个主要方法 - Run multiple main methods in Java with Intellij 当我们在eclipse上运行程序时,主函数如何获得参数? - How can the main function gets its argument when we run a program on eclipse? 我如何在 Intellij 中运行 java 卡小程序? - How i can run java card applet in Intellij? 运行/调试文件的 main() 时,如何在 IntelliJ 中使用 SQLServerDriver? - How can I use the SQLServerDriver in IntelliJ when I run/debug a file's main()? 如何在 intellij 中处理多个 Java 项目? - How can I work with multiple Java projects in intellij? 如何使用Eclipse中的运行配置参数将空参数传递给我的Java main方法? - How can I pass null arguments to my Java main method using run configuration arguments in Eclipse? 如何在Java应用程序中从Main方法运行线程? - How can I run thread from Main method in Java application? 如何从主要活动中运行 java.class - How can I run a java.class from Main Activity 如何在intellij中为Java纠正多行中单个语句的缩进 - How to correct indentation for single statement in multiple lines for java in intellij
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM