I want to convert from String numbers "12345"; to five separate ints
how can I do that?
thanks
Printable View
I want to convert from String numbers "12345"; to five separate ints
how can I do that?
thanks
Integer.parseInt() takes a String and turns it into a number.
To get each character use the String.toCharArray();
For example you can do the following:
BTW the n+"" is a shortcut to turn n into a String.Code:String num = "12345";
char[] arr = num.toCharArray();
for (char n : arr)
{
int i = Integer.parseInt(n + "");
print(i);
}
very well
thanks I know that was a silly question
sorry
One of our friend have made this simple explanation bout Strings in Java if u need some added reference besides the one from sun, here's the link
http://www.java-forums.org/java-book...va-string.html
Hey i have a question
Authentication A1 = new Authentication(1);
System.out.println("Enter ID");
A1.SetID(Integer.parseInt(System.in.read()));
System.out.println(A1.GetID());
Authentication is the name of Class i made
Problem is when i dont use Interger.parseInt if i enter value 1 it prints it 50
and if i convert that to int it gives me error :S
it was usefule