PDA

Click to See Complete Forum and Search --> : Cast String to int....*Solved*


NoteMe
May 6th, 2003, 03:37 PM
Ok I have a car number like this

DJ44444

in a String object. Now I want the three numbers in the middle to be casted to a int. I know I kan use substring() to get the numbers out into a new string, but how do I convert them to an integer variable? This might be a dumb question but please answer. Thanks.

NoteMe
May 6th, 2003, 03:53 PM
I got it....It was a stupid mistake...

Dillinger4
May 6th, 2003, 11:07 PM
Sorry. I just couldn't resist. :D

public class Z{
public static void main(String[] args){
String s = new String("DJ12345");
String s2 = s.substring(2,5);
int i = Integer.parseInt(s2);
System.out.println(i + i);
}
}

NoteMe
May 8th, 2003, 10:39 AM
It's ok....I just didn't think that parseInt was the right function. It said throws numberFormatException an I was scared and did run away...:D