Click here to Skip to main content
Rate this: bad
good
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
Edited 21-Oct-12 7:11am
v6
Comments
CPallini at 20-Oct-12 17:07pm
   
What code?
javamontrealman at 20-Oct-12 17:24pm
   
hi, sorry i was editing a little bit

1 solution

Rate this: bad
good
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.
  Permalink  
v2
Comments
javamontrealman at 20-Oct-12 17:25pm
   
im fairly new, could you maybe get me started by giving some hints
Nelek at 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 at 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
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Oct 2012
Copyright © CodeProject, 1999-2014
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