-1

I'm just a beginner in Java. Please help in executing this simple program. It throws an exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at sum.main(sum.java:7)

The Program

class sum {
    public static void main(String args[]){
       int a,b,c;

       a=Integer.parseInt(args[0]);
       b=Integer.parseInt(args[1]);
       c=a+b;

       System.out.println(c);
    }
}
ma3stro
  • 313
  • 2
  • 11
Jijin
  • 3
  • 2

1 Answers1

5

You need to pass at least two parameters to your java program.

For example:

java sum 10 45

If you start the program from an ide (eclipse or IntelliJ or others), for default no parameters is passed to run the program. You need to edit the run configuration manually adding them. I use IntelliJ, in IntelliJ this is done setting a field named Program Arguments. In eclipse is something similar.

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56