This is the error i get..
Enter employee name: Bryan
Enter employee's salary: 123
Enter employee name: Mark
Enter employee's salary: 456
Enter employee name: Fajutag
Enter employee's salary: 789
Enter employee name: qwe
Enter employee's salary: 32
Enter employee name: qew
Enter employee's salary: 312
Enter employee name: qew
Enter employee's salary: 65
Enter employee name: qwe
Enter employee's salary: 654
Enter employee name: qwe
Enter employee's salary: 654
Enter employee name: qwe
Enter employee's salary: 654
Enter employee name: qwe
Enter employee's salary: 645

Number of employees with salaries of at least P 18,000 :0
Number of employees with salaries of below P 18,000 :10
Total salary paid to all the employees : P4384
java.lang.ArrayIndexOutOfBoundsException: 10
    at Salary.Employee(Salary.java:41)
    at Salary.main(Salary.java:85)
Exception in thread "main" 
Process completed.

What is the solution to this error 
java.lang.ArrayIndexOutOfBoundsException: 10
    at Salary.Employee(Salary.java:41)
    at Salary.main(Salary.java:85)
Exception in thread "main"

Recommended Answers

All 5 Replies

java.lang.ArrayIndexOutOfBoundsException: 10

the problem is: your array is declared as an array of 10 elements, which sets the valid index-range from 0 to 9, yet somewhere you are trying to access the element on index 10

try by resetting the value from ctr1. also, you may want to re-format the output you are generating.

System.out.println("Name of employees with salaries of at least P 18,000 :");
                System.out.print(name[ctr] + salary[ctr1]);

'll be a lot more clear if you print it like this:

System.out.println("Name of employees with salaries of at least P 18,000 : " + name[ctr] + salary[ctr1]);

but where must be the problem part?..
thanks for your coed for shortening my code..

java.lang.ArrayIndexOutOfBoundsException: 10
at Salary.Employee(Salary.java:41)

This also tells you the problem is on line 41 of Salary.java

i already solved this.. thanks to your help..

and how exactly did you solve it? by re-setting the ctr1 variable, as I suggested?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.