Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code is supposed to show the percentage of leading digits in an array and return another array. When I tested it, I kept getting the message that exception in thread main java.lang.arrayindexoutofboundsexception4. Could someone tell me why?
Posted
Updated 21-Oct-12 7:11am
v6
Comments
CPallini 20-Oct-12 17:07pm    
What code?
javamontrealman 20-Oct-12 17:24pm    
hi, sorry i was editing a little bit

1 solution

Hint: Look at this line
Java
digitpercentage [p] = calculateLeadingDigit ((int) numbers [p])/numbers.length;

Your p value ranges from 0 to 9. But does numbers length varies same? You do numbers[p], is not there a possibility of index out of range?

Debug step wise and see how the execution is happening and what are the values assigned.
 
Share this answer
 
v2
Comments
javamontrealman 20-Oct-12 17:25pm    
im fairly new, could you maybe get me started by giving some hints
Nelek 20-Oct-12 18:40pm    
That's what he did. He recommended you to start using the debugger and I agree with him. It can help you find the errors and learn from them, what actually is the best way of learning
Sandeep Mewara 21-Oct-12 1:48am    
I exactly did that. Gave a hint and the way to resolve it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900