An interview question:
The Java implementation transforms an int array into an int integer. For example: int[] arr = new int[]{1,2,3,4,5}; Becomes 12345
/** * created by leo on 15/10/27. */public class interview { public static void main (String[] args) { system.out.println (parseint (new int[]{1,2,3,4,5})); system.out.println (Integer.parseint ("12345")); } /** * 12345 * @param arr * @return */ public static final int parseint (Int[] arr) { int length = arr.length; int total = 0; for (int i = 0; i < length; i++) { int num = arr[i]; total = total + Calculateweightnum (num, length - (i + 1)) ; } return total; } private static int calculateweightnum (int num , int Numoften) { int result = num; for (int i = 0; numoften > 0 & & i < numoften; i++) { result = result * 10; } return result; }}
This article is from the "Java Small Novices" blog, be sure to keep this source http://leokongwq.blog.51cto.com/1310215/1706710
Change an int array to an int integer