int array to int number in Java
arrays, int, java
Solution
Start with a result of `0`. Loop through all elements of your `int` array. Multiply the result by `10`, then add in the current number from the array. At the end of the loop, you have your result.
- Result: 0
- Loop 1: Result * 10 => 0, Result + 1 => 1
- Loop 2: Result * 10 => 10, Result + 2 => 12
- Loop 3: Result * 10 >= 120, Result + 3 => 123
This can be generalized for any base by changing the base from `10` (here) to something else, such as `16` for hexadecimal.
Problem
I'm new on this site and, if I'm here it's because I haven't found the answer anywhere on the web and believe me: I've been googling for quite a time but all I could find was how to convert a number to an array not the other way arround. I'm looking for a simple way or function to convert an int array to an int number. Let me explain for example I have this : ``` int[] ar = {1, 2, 3}; ``` And I want to have this: ``` int nbr = 123; ``` In my head it would look like this (even if I know it's not the right way): ``` int nbr = ar.toInt(); // I know it's funny ``` If you have any idea of how I could do that, that'd be awesome.