How to write a program to convert string to number without using Integer.parseInt() method3 min read

In this tutorial, I am going to show you how to convert string into integer without using Integer.parseInt() method in java.

We will be using Java 8 but you can use any version of java.

This java problem often are asked in interview. So in the interview the interview will ask you to write a program to convert the string into the integer without using parseint method.

Convert string to number without using Integer.parseInt()

so we have to write the code so let’s go write the program to convert the string into the integer.
let’s do it go into an IDE to create in your class that is a string to int here is my main method.

Write a string numbers. Here is my string that is a 8 5 5 4 3 1.

Before doing the conversion I’m going to tell you the logic of this how can we convert the string string in into the integer. We have to split this string into a single single characters and after that we can catch the ASCII value of each and every character and and subtracting the ASCII value of zero number.
ASCII value from these numbers a skew value so I am going to show you how it will work in this code.

Here I wrote a simple template to a more understanding.


ASCII value of these zero is a port 48 so Here we can see the a scale of zero idea is portaits. 49 is 1 and 50 for 3. This is the ASCII values for integers. 48 and for the port it is the ASCII value of 0 so we can find other numbers that way.

We can write the code for splitting these strings into the characters and after splitting we can subtract in from the 0. We can get the the actual value of each and every character. Let’s do it “for loop” that we need to split these string into the single single characters.

charAt method is going to return a ASCII postion of single current char. We can get these single character values and after that we are storing inside the sum. But before we need to multiply every decimal place to 10.


Let’s run again here here is the output so this is from the this post all so if you like this post . Please do consider to subscribe our youtube channel and also hit the like button thanks for watching.

Leave a Comment