How to Convert String to Integer using ASCII

How to Convert String to Integer using ASCII
SOURCE : StringToInteger.java

public class StringToInteger {

public static void main(String[] args) {

String str = "4536";
int sum = 0;
char[] itt = str.toCharArray();
int asciizero = (int) '0';
for (Character c : itt) {

int tempascii = (int) c;
sum = (sum * 10) + (tempascii - asciizero);
}
System.out.println(sum);
}

}


INPUT

String str = "4536"



OUTPUT

4536






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment