+ 1

Why am I getting java.lang.ArrayIndexOutOfBoundsException on the 8th line and how to remove the error?

import java.io.*; class cubeC { public static void main(String args[]) { System.out.println("Please enter the number to find the cube of a digit: "); int n=Integer.parseInt(args[0]); int c=n*n*n; System.out.println("The Cube of Number is : "+c); } }

17th Sep 2017, 3:38 AM
Nidhi
Nidhi - avatar
1 Respuesta
+ 8
No argument was passed through to args, so most probably it does not contain any data. This means that accessing args[0] will trigger the exception.
17th Sep 2017, 3:50 AM
Hatsy Rei
Hatsy Rei - avatar