Results 1 to 2 of 2
Thread: Question about what this do.
- 07-03-2010, 07:12 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 34
- Rep Power
- 0
Question about what this do.
can somebody explain me the use of this statement?Java 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. }
especially the if else statement w/ math.pow.
- 07-03-2010, 08:35 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
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
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
Please help me PLEASe with this question
By javanew in forum New To JavaReplies: 2Last Post: 03-26-2010, 12:45 PM -
RMI question
By alvandrood in forum New To JavaReplies: 1Last Post: 09-14-2009, 12:36 PM -
Need help on this question
By Deon in forum New To JavaReplies: 3Last Post: 01-27-2008, 03:58 PM -
question about rmi
By leonard in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:19 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks