java - Get the number of digits in an array in the place of 'X' -


I need to create a recursive function which gives the number of digits in the array.

Is this far away from me

  public constant int rec (int [] arr, int size) {int numbers = 0; If (size> 0) {numbers = String.valueOf (arr [shape]). Length () + rick (arr, size-1); // the length of the digits in the array} return number; }  

But the problem is that when it goes there it crashes the debug.

I think this is String.valueOf which makes this accident, by any idea how can I get the number of digits in the X-th position of the array? (Number of digits in arr [x] )

The issue is that You were using a 5 - size and you can have 5 elements in some elements, 5 (before editing your question). Every time you are recalling numbers resetting 0 with recursive calls.

Try calling Call Rec (array, array.length - 1) from your main method:

  public static inte Rick (int [] arr, int size ) {If (size> = 0) {return 1 + (int) Math.floor (Math.log10 (arr [size]) + Rec (arr, size) - 1); // Or keep it simple to use String.valueOf (arr [shape]) 1+ (int) Math.floor (Math.log10) (instead of arr (size)) Length ()) 0; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -