Click here to Skip to main content
12,890,970 members (53,877 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
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 20-Oct-12 10:35am
Updated 21-Oct-12 7:11am
CPallini 20-Oct-12 17:07pm
What code?
javamontrealman 20-Oct-12 17:24pm
hi, sorry i was editing a little bit

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hint: Look at this line
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.
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100