share

Saturday, 17 January 2015

Convert string into number in java

  A string contains a number such that
string str="1023";
then calculate a number num=1023;
 call method int convertStringToNumber(char []myNumber);
char[]myNumber=str.toCharArray();
int num=int convertStringToNumber(char []myNumber);
  int convertStringToNumber(char []myNumber){
        int i=0;
        int num=0;
        int zeroAscii = (int)'0';
         while (i<myNumber.length) {
            int charAscii=(int)myNumber[i];
            num=num*10+(charAscii-zeroAscii);
             i++;
            }
            return num;
    }






 Related Posts:


Check a string value is Integer or not in java. (Solution).

Check ia string is hexadecimal number or not (Solution).

Generate Combination in java (Solution).

Generate permutation of string(Solution).

Reverse string in java (Solution).

Find duplicate characters with occurrences in a string(Solution).

Permutation of a number(Soluion).

Split the String in java(Solution).

Convert string into number in java(Solution).

Swap two strings without using any variable(Solution).

Get a number from a string in java(Solution).

Add Two Big Number In Java(Solution).

Expand String(Solution).

Reverse String (Solution).

No comments:

Post a Comment