Click here to Skip to main content
11,582,849 members (72,466 online)
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 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 124
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,403
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 696
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 503


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 21 Oct 2012
Copyright © CodeProject, 1999-2015
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