-4

I am New to Java Coding if i run below Code the Error is Coming.. Please Help

public class LeapYear {

    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int sum  = a + b;
        int prod = a * b;
        int quot = a / b;
        int rem  = a % b;

        System.out.println(a + " + " + b + " = " + sum);
        System.out.println(a + " * " + b + " = " + prod);
        System.out.println(a + " / " + b + " = " + quot);
        System.out.println(a + " % " + b + " = " + rem);
        System.out.println(a + " = " + quot + " * " + b + " + " + rem);
    }
}

O/p:::

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at LeapYear.main(LeapYear.java:4)
azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

0

If you're running this on netbeans, you can pass arguments into the main method by right clicking on the project, pick properties (it's at the bottom), click on the run category and then underneath Runtime Platform and Main Class is a text field to enter arguments.


If you're calling it from the command line, e.g. running javac and passing it the main class name, just add two command line arguments after the class name.

Rick
  • 576
  • 3
  • 12