# Question about what this do.

• 07-03-2010, 07:12 AM
Syfer
Code:

```for(int i = 0; i<inputting; i++){           System.out.print("Enter Number "+(i+1) + ": ");             num[i]= kbd.next();             System.out.print("Enter Original Base: "+(i+1) + ": ");             x[i] = Integer.parseInt(kbd.next());             int l = num[i].length();             int v = 0;             for(int j = l-1; j>=0; j--){                 if(Character.isLetter(num[i].charAt(v))){                     a = calculate(num[i].charAt(v));                 }                   else                     a = Integer.parseInt(Character.toString(num[i].charAt(v)));                 z = z + (a*(int)Math.pow(x[i], j));                 v++;                                 //  Returns the value of the first argument raised to the power of the second argument.             }```
can somebody explain me the use of this statement?

especially the if else statement w/ math.pow.
• 07-03-2010, 08:35 AM
JosAH
Quote:

Originally Posted by Syfer
Code:

```for(int i = 0; i<inputting; i++){           System.out.print("Enter Number "+(i+1) + ": ");             num[i]= kbd.next();             System.out.print("Enter Original Base: "+(i+1) + ": ");             x[i] = Integer.parseInt(kbd.next());             int l = num[i].length();             int v = 0;             for(int j = l-1; j>=0; j--){                 if(Character.isLetter(num[i].charAt(v))){                     a = calculate(num[i].charAt(v));                 }                   else                     a = Integer.parseInt(Character.toString(num[i].charAt(v)));                 z = z + (a*(int)Math.pow(x[i], j));                 v++;                                 //  Returns the value of the first argument raised to the power of the second argument.             }```
can somebody explain me the use of this statement?

especially the if else statement w/ math.pow.

You didn't write this piece of code yourself did you? No? Good, because it's a lousy way to convert a String representation of a number in any base to an integral number; w.r.t. that pow( ... ) method: the author commented the method in the last line of the 'else-part' and because it's a method from the Math class it is completetly documented in the API documentation. My tip: throw that piece of code away and read the API documentation for the Integer class; it does exactly what you want and it does it without using that the pow( ... ) method.

kind regards,

Jos