+ 3

Guys how can i convert String into Integer in simple way ?

here is my code the result of integer should be 18. https://code.sololearn.com/cSVeHW8s3aAM/?ref=app

27th Jan 2018, 2:10 PM
šŸ¦‹FEATHERšŸ¦‹
šŸ¦‹FEATHERšŸ¦‹ - avatar
5 Answers
+ 17
public class Program { public static void main(String args[]) { String s="2018"; int l=s.length(); int x=s.indexOf('0'); System.out.println(Integer.parseInt(s.substring(x+1,l))+1-1); } } //use Integer.parseInt ()
27th Jan 2018, 2:18 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
yes,thats correct
27th Jan 2018, 2:21 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
String s ="2018"; int b=Integer.parseInt(s);
27th Jan 2018, 2:18 PM
LordHill
LordHill - avatar
+ 3
in a particular variable for example int j=Integer.parseInt(s); //is that right.
27th Jan 2018, 2:20 PM
šŸ¦‹FEATHERšŸ¦‹
šŸ¦‹FEATHERšŸ¦‹ - avatar
+ 2
ok, thanks.
27th Jan 2018, 2:22 PM
šŸ¦‹FEATHERšŸ¦‹
šŸ¦‹FEATHERšŸ¦‹ - avatar