Results 1 to 2 of 2
  1. #1
    Syfer is offline Member
    Join Date
    Jun 2010
    Posts
    34
    Rep Power
    0

    Default Question about what this do.

    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.
                }
    can somebody explain me the use of this statement?

    especially the if else statement w/ math.pow.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,536
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Syfer View Post
    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.
                }
    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

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Please help me PLEASe with this question
    By javanew in forum New To Java
    Replies: 2
    Last Post: 03-26-2010, 12:45 PM
  3. RMI question
    By alvandrood in forum New To Java
    Replies: 1
    Last Post: 09-14-2009, 12:36 PM
  4. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 03:58 PM
  5. question about rmi
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •