How would I go about converting a string to an integer?
Say someone enters a 4 digit string. Like 1234.
Could I use the place of each digit and work with it? Pretty much, I wanna get 1 from the string "1234" and put it in a variable. Then get 2 from the string "1234" and put it in its own variable, and so forth.
Like take the 0 spot, which would be 1. and say change it to something else?
I know I could do something like
public class GetIntFromString {
public static void main(String[] args)
{
String str = "1234";
for(int i = 0; i < str.length(); i++)
{
str.charAt(i);
System.out.println(i);
}
}
}
Also do the same thing for each digit of the string. Is this possible without using an array?