public static void main(String[] args) {
int a, b, c;
a = Integer.parseInt(args[0]);//需要向主函数中传入参数
b = Integer.parseInt(args[1]); //run configurations;
c = Integer.parseInt(args[2]);
int i = sum(a, b, c);
System.out.println(a + "+" + b + "*" + c + "=" + i);
public static int sum(int a, int b, int c) {
int sum = 0;
sum = a + mul(b, c);
return sum;
public static int mul(int b, int c) {
int mul = b * c;
return mul;
public class GreenLeaf {
public static final String TYPE = "WhiteFlower";
public static void main(String[] args) {
for (String a : args){
System.out.println(a);
System.out.println(TYPE);
上面的简单示例代码将打印传入的参数及一个字符串。
一、使用IDE集成开发环境运行Java main方法(Idea展示)
1.首先,点击菜单Run->Edit Configurations:
2.然后,在主类的Configuration -> Program arguments中输入你的参数,多个参数以空格分隔: