DEV Community

Cover image for Convert String to Integer

Convert String to Integer

suchitra_13 profile image Suchitra ・1 min read

Today i stacked in a problem then i knew this and so i want to share with you!

It is a very simple problem but i think most of the people still doesn't know about it because we generally use some predefined functions for it such as
Integer.parseInt() and Integer.ValueOf()
Here is the user-defined function for converting string to integer.
For example:Input- String s="2345"
Output- int a=2345

import java.util.*;
class Solution
public satic void main(String args[])

String s="2345";
int d=Int_val(s);
public static int Int_val(String s)
int result=0;
for(char c:s.toCharArray())

return result;

I hope you like

Discussion (0)

Forem Open with the Forem app