4

This is a beginner question. I am trying to run a java program from cmd with arguments. This is my class:

public class Test{
    public static void main(String[] args){
        System.out.println("This is a test");
        System.out.println(args.length);
    }
}

I can run it without arguments successfully. How can I put for example 5 and 6 as arguments in my program?

All the other answers I found where just to run the program. I already know how to do that. I was not able to find how to run the program using arguments.

4
  • 1
    check this docs.oracle.com/javase/tutorial/essential/environment/… Commented Nov 8, 2016 at 15:28
  • All the other answers I found where just to run the program. I know how to do that. I was not able to find how to run the program with arguments @jay Commented Nov 8, 2016 at 15:32
  • you just write them after Commented Nov 8, 2016 at 15:32
  • How do you run your program? In a command prompt or using an IDE? Commented Nov 8, 2016 at 15:36

1 Answer 1

15
java Test arg1 arg2 arg3 ...

or

java Test "arg1 arg2 arg3" ...

More details here Command-Line Arguments

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.