-3

THIS IS THE CODE here I want to take value from cmd and use that to get the output. Please let me know if there is any other problem. Thanks

class Basic
{
int b;
public void gd(int c){
b=c;
}
}


class HRA extends Basic
{

double hra=(0.25*b);

}


class DA extends HRA
{

double da=(0.75*b);

}


class PF extends DA
{

double pf=(0.12*b);

}

class Netsalary extends PF
{

double ns=b+hra+da+pf;

void display()
{

System.out.println("The net salary = "+ns);

}

}


class Netsalmain
{

public static void main(String arb[])
{

int a= Integer.parseInt(arb[0]);

Netsalary ob=new Netsalary();

ob.gd(a);    
ob.display();

}

}

error is showing like this

E:>java Netsalmain Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Netsalmain.main(iop.java:54)

  • 1
    you aren't passing any arguments to your program to use and so arb has size 0 and therefore index 0 is an out of bounds exception – RAZ_Muh_Taz Apr 02 '18 at 15:47

1 Answers1

0

You are not passing the command line argument and trying to access it that’s is why you are getting array index out of bound. If you are using IDE then go into run configuration and give the parameter. If you are trying to run via cmd then give the command line argument while running.

Raman Mishra
  • 2,392
  • 2
  • 10
  • 30