Java atoi atoi(String str)

Here you can find the source of atoi(String str)

Description

atoi

License

Open Source License

Declaration

public static int atoi(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static int atoi(String str) {
        int retVal = 0;
        for (int i = 0; i < str.length(); i++) {
            retVal += (str.charAt(i) - '0') * power(1, str.length() - i - 1);
        }/* ww  w. j a  va  2s . co m*/
        return retVal;
    }

    private static int power(int val, int numOfPower) {
        for (int i = 0; i < numOfPower; i++) {
            val *= 10;
        }
        return val;
    }
}

Related

  1. atoi(String s)
  2. atoi(String s)
  3. atoi(String s)
  4. atoi(String s, int pos, int base)
  5. atoi(String str)
  6. atoi(String[] s)