0

How can I get this resolved? This is a code, and every time I try to run it this error shows up "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at IntOps.main(IntOps.java:5)"

public class IntOps {

        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);
        }
}

Please, help me to understand why it is not working. Thanks.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 1
    You're running the program without any args, and so it makes sense that the exception should be thrown. Make sure that when you run the program, you pass in command-line arguments. Eclipse has ways to do this in the Run menu as per one of the duplicates used to close this question. – Hovercraft Full Of Eels Feb 13 '23 at 20:10
  • 1
    Follow those linked questions to understand the important step you're missing before accessing members of an array (the `args[0]`). – Rogue Feb 13 '23 at 20:14
  • Thank you guys, I'm just noob at this. – David Ladino Feb 13 '23 at 20:33
  • I understand, we all were newbies at one time or another, but in the future, best to first search on the error message before asking. A Google search such as [site:stackoverflow.com java ArrayIndexOutOfBoundsException: Index 0](https://www.google.com/search?q=site%3Astackoverflow.com+java+ArrayIndexOutOfBoundsException%3A+Index+0) (please click on this link to see what it brings up and how it works) can at least give you some ideas from similar questions, and help you make a more specific and less of a duplicate question. – Hovercraft Full Of Eels Feb 13 '23 at 21:31

0 Answers0